Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <cstring>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- #define p 5
- int pp[5005];
- int hash[5005];
- int kol = 0;
- int hsh[5005];
- char buf[5005];
- char f(char c){
- switch(c){
- case 'A':
- return 1;
- case 'C':
- return 2;
- case 'G':
- return 3;
- case 'T':
- return 4;
- }
- return -1;
- }
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- cin >> buf;
- int n = strlen(buf);
- pp[0] = 1;
- for (int i=1; i<5005; i++){
- pp[i] = pp[i-1] * p;
- }
- hsh[0] = 0;
- for (int i=0; i<n; i++){
- buf[i] = f(buf[i]);
- hsh[i+1] = buf[i] + hsh[i] * p;
- }
- int ret = 0;
- for (int len=1; len<n; len++){
- int kol = 0;
- for (int i=0; i<n-len+1; i++){
- hash[kol++] = hsh[i+len] - hsh[i] * pp[len];
- }
- sort(hash, hash + kol);
- int ps = -1;
- for (int i=1; i<kol; i++){
- if (hash[i] == hash[i-1]){
- if (ps == -1 || hash[i] != hash[ps]){
- ps = i;
- ret++;
- }
- }
- }
- }
- printf("%d\n%lf", ret, clock());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement