Cod sursa(job #694657)

Utilizator FayedStratulat Alexandru Fayed Data 27 februarie 2012 22:34:24
Problema Aho-Corasick Scor 25
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include<fstream>
#include<cstring>
#define Nmax 1000000
#define nmax 10000
using namespace std;

ifstream f("ahocorasick.in");
ofstream g("ahocorasick.out");
short n;
 char s[Nmax];
char xs[nmax];
int V[19];
 int main()
 {
int nr=0;
     int k,j;
     f>>s;
f>>n;
for(int i=1;i<=n;i++)
{
    f>>xs;
 V[i]=0;
 for(j=0;j<strlen(s);j++)
 {
     nr=0;
   for(k=0;k<strlen(xs);k++)
   {
      if(s[k+j]!=xs[k])
  break;
        nr++;
     if(nr==strlen(xs))

     V[i]++;
             }
 }
}

for(int i=1;i<=n;i++)
 g<<V[i]<<endl;
 f.close();
 g.close();
 return 0;

 }