Pagini recente » Cod sursa (job #2401805) | Monitorul de evaluare | Cod sursa (job #1874658) | Statistici Tutuianu Razvan Andrei (Rezvann) | Cod sursa (job #1467864)
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <tr1/functional>
using namespace std;
int main()
{ifstream f("strmatch.in");
ofstream g("strmatch.out");
vector<int> a;
string n,m;
getline(f,m);getline(f,n);
tr1 ::hash<char> hsh;
long q=0,w=0, t=0, x=0, v=m.length(), r=n.length();
for (long i=0;i<v;i++){
w=w+hsh(m[i]);
}
for (long i=0;i<v;i++){
q=q+hsh(n[i]);
}
for (long i=0;i<=r-v;i++){
if ((q==w)){
for (long j=0;j<v;j++){
if (m[j]==n[i+j]) ++t;
if (t==v) {a.push_back(i);t=0;++x;}
}
}
q=q+hsh(n[i+v])-hsh(n[i]);
}
g<<x<<'\n';
for (long i=0;i<x;i++){
g<<a[i]<<' ';
}
return 0;
}