Pagini recente » Cod sursa (job #2788424) | Cod sursa (job #514501) | Cod sursa (job #2150082) | Cod sursa (job #902224) | Cod sursa (job #2473709)
#include <bits/stdc++.h>
using namespace std;
ifstream f("abc2.in");
ofstream g("abc2.out");
typedef unsigned int ii;
const int NMAX = 666013;
string s,st;
vector <ii> v[NMAX + 2];
inline bool is(ii x){
ii i = x % NMAX;
for(ii j = 0 ; j < v[i].size() ; j++)
if(v[i][j] == x)
return 1;
return 0;
}
inline void add(ii x){
ii i = x % NMAX;
v[i].push_back(x);
}
int main(){
ios::sync_with_stdio(false);
f.tie(NULL);
ii i,x,y,ans = 0,j;
f >> s;
while(f >> st){
x = 0;
y = 1;
for(i = 0 ; i < st.size() ; i++){
x += (st[i] - 'a' + 1) * y;
y *= 3;
}
if(!is(x))
add(x);
}
x = 0 ; y = 1;
for(i = 0 ; i < st.size() ; i++){
x += (s[i] - 'a' + 1) * y;
y *= 3;
}
if(is(x))
ans++;
y /= 3;
for(i = st.size() ; i < s.size() ; i++){
x -= (s[i - st.size()] - 'a' + 1);
x /= 3;
x += y * (s[i] - 'a' + 1);
if(is(x))
ans++;
}
g << ans;
return 0;
}