Pagini recente » soldiers | Cod sursa (job #200238) | testare_olimpiada | Cod sursa (job #1682792) | Cod sursa (job #2296871)
#include<cstdio>
#include<vector>
#include<string>
#include<fstream>
using namespace std;
string text;
char cuv[25];
vector <int> hh[10041];
int lung[10041];
ifstream cin("abc2.in");
void hashuire(long long x)
{
int m;
int i;
m = x % 10041;
for(i = 0; i < lung[m]; ++ i)
if(hh[m][i] == x / 100)
return ;
hh[m].push_back(x / 100);
++ lung[m];
}
bool verif(long long x)
{
int m;
int i;
m = x % 10041;
for(i = 0; i < lung[m]; ++ i)
if(hh[m][i] == x / 100)
return 1;
return 0;
}
int main()
{
freopen("abc2.out", "w", stdout);
unsigned int x, p;
int n, i, j, nr = 0, m = 0;
cin>>text;
n = 0;
n=text.size();
while(cin>>cuv)
{
x = 0;
if(m == 0)
{
while(cuv[m] != '\0')
{
++ m;
}
}
for(i = 0; i < m; ++ i)
x = x * 3 + cuv[i] - 'a';
hashuire(x);
}
x = 0;
p = 1;
for(i = 1; i < m; ++ i)
p = p * 3;
for(i = 0; i < n; ++ i)
{
x = x * 3 + text[i] - 'a';
if(i >= m - 1)
{
nr += verif(x);
x = x % p;
}
}
printf("%d\n", nr);
return 0;
}