Cod sursa(job #101711)

Utilizator fireatmyselfBogdan-Alexandru Stoica fireatmyself Data 13 noiembrie 2007 19:24:34
Problema Abc2 Scor 0
Compilator c Status done
Runda Happy Coding 2007 Marime 1.41 kb
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define S ((1<<23)-1)

int V[10000002][2], Nr;
char ss[10000002], ss2[50002];

int main()
{
        int i, j, l, n, nv = 0;
        long long hash, hash2, x, y;

        srand(time(0));

        freopen("abc2.in", "r", stdin);
        gets(ss);
        n = strlen(ss);
        scanf(" ");
        gets(ss2);
        l = strlen(ss2);
        n = n-l;

        for (i = 0; i <= n; i++)
        {
            hash = hash2 = 0;
            for (j = 0; j < l; j++)
            {
                x = (hash<<13);
                y = (hash2<<23);
                hash = (hash+x+ss[i+j])&S;
                hash2 = (hash2+y+ss[i+j])&S;
            }
            V[nv][0] = hash; V[nv++][1] = hash2;
        }

        hash = y;
        for (j = 0; j < l; j++)
        {
            x = (hash<<13);
            hash = (hash+ss2[j])&S;
        }
//        Nr += V[hash][0];
//        V[hash][0] = 0;

        while (scanf(" %s", ss2)!=EOF)
        {
                hash = y;
                for (j = 0; j < l; j++)
                {
                    x = (hash*y);
                    hash = (hash+ss2[j]+x)&S;
                }
//                Nr += V[hash][0];
//                V[hash][0] = 0;
        }

        freopen("abc2.out", "w", stdout);
        printf("%d\n", Nr);

        return 0;
        
}