Pagini recente » Cod sursa (job #180593) | Cod sursa (job #1288208) | Cod sursa (job #2206944) | Cod sursa (job #2593691) | Cod sursa (job #102052)
Cod sursa(job #102052)
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#define maxn 600003
#include <set>
#include <bitset>
using namespace std;
char T[10000001];
int n;
//bool used[10000001];
bitset<10000001> used;
struct nod { long long v; nod *n;};
set<long long> H[maxn];
//nod *H[2];
/*
inline void insert(char x[])
{
int n=0;
while(x[n]>='a' && x[n]<='c') ++n;
long long t=0;
for(int i=0;i<n;++i)
t=4*t+x[i]-'a'+1;
int h=(int)(t%maxn);
for(nod *tt=H[h]; tt; tt=tt->n)
if(tt->v==t)return ;
nod *p=new nod;
p->v=t;
p->n=H[h];
H[h]=p;
}
*/
inline int insrt(char x[])
{
int n=0;
while(x[n]>='a' && x[n]<='c') ++n;
long long t=0;
for(int i=0;i<n;++i)
t=4*t+x[i]-'a'+1;
int h=(int)(t%maxn);
H[h].insert(t);
}
void read()
{
int i, j;
freopen("abc2.in","r",stdin);
gets(T);
n=0;
while(T[n]>='a' && T[n]<='c') ++n;
int nr=0;
while(!feof(stdin))
{
char x[32];
gets(x);
insrt(x);
}
}
/*
inline int find(long long v)
{
int h=(int)(v%maxn);
for(nod *p=H[h]; p ; p=p->n)
if(p->v==v)return 1;
return 0;
}
*/
inline int fnd(long long v)
{
int h=(int) (v%maxn);
if(H[h].find(v)==H[h].end()) return 0;
return 1;
}
int main()
{
read();
freopen("abc2.out","w",stdout);
int i, j;
long long p;
int nr=0;
for(i=0;i<n;++i)
if(!used[i])
{
p=0;
for(j=i;j<i+20;++j)
{
p=p*4+T[j]-'a'+1;
// printf("%lld\n", p);
if(fnd(p) && !used[i])
{
++nr;
used[i]=1;
break;
}
}
}
printf("%d\n", nr);
return 0;
}