Pagini recente » Cod sursa (job #2758231) | Cod sursa (job #1063292) | Cod sursa (job #1073275) | Cod sursa (job #436258) | Cod sursa (job #1727340)
#include <fstream>
#include <cstring>
#include <set>
#include <map>
#define MOD 666013
#define BASE 3
using namespace std;
ifstream f("abc2.in");
ofstream g("abc2.out");
char cuv[50] , prop[10000005];
unsigned int n , m , nr;
bool mp[1500000];
int main() {
f >> prop;
m = strlen(prop);
while (f >> cuv) {
unsigned int hash1 = 0;
n = strlen(cuv);
for (int i = 0; i < n; ++i) {
hash1 = (hash1 * BASE + (cuv[i] - 'a')) % MOD;
}
mp[hash1] = 1;
}
unsigned int P1 = 1, hash1 = 0;
for (int i = 0; i < n; ++i) {
hash1 = (hash1 * BASE + (prop[i] - 'a')) % MOD;
if (i) {
P1 = (BASE * P1) % MOD;
}
}
if (mp[hash1] == 1) {
++nr;
}
for (int i = n; i < m; ++i) {
hash1 = ((hash1 - ((prop[i - n] - 'a') * P1) % MOD + MOD) * BASE + (prop[i] - 'a')) % MOD;
if (mp[hash1] == 1) {
++nr;
}
}
g << nr;
return 0;
}