Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 11:48:55
2016-05-28 11:47:28
2016-05-28 11:20:46
Task:DNA sequence
Sender:Team Purkka
Submission time:2016-05-28 11:48:55
Status:READY
Result:ACCEPTED

Show test data

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:27:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j <= s.length() - i; j++) {
                                       ^

Code

#include <bits/stdc++.h>
#define ll long long

using namespace std;

int calc_hash(const string &s, int off, int len) {
  int r=0;
  for(int i=off;i<off+len;i++){
    char c=s[i];
    if(c=='A')c=1;
    else if(c=='T')c=2;
    else if(c=='G')c=3;
    else c=4;
    r=r*5+c;
  }
  return r;
}

int v[10000000];

int main () {
  string s;
  cin>>s;
  int n;
  cin>>n;
  for (int i = 1; i <= min(10, (int)s.length()); i++) {
    for (int j = 0; j <= s.length() - i; j++) {
	v[calc_hash(s, j, i)] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
      string x;
      cin>>x;
      if (v[calc_hash(x,0,x.length())]) cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
  }
}