Pagini recente » Cod sursa (job #734404) | Cod sursa (job #2264060) | Cod sursa (job #192635) | Cod sursa (job #1107908) | Cod sursa (job #1467842)
#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; int v,t=0,x=0,r,w;
getline(f,m);getline(f,n);
tr1 ::hash<string> hsh; tr1::hash<int> hin;
long long q=hsh(m);v=m.length();r=n.length();w=hsh(n.substr(0,v));
for (int i=0;i<=r-v;i++){
if ((q==w)){
for (int j=0;j<v;j++){
if (m[j]==n[i+j]) ++t;
if (t==v) {a.push_back(i);t=0;++x;}
}
}
w=w+hin(n[i+v])-hin(n[i]);
}
g<<x<<'\n';
for (int i=0;i<x;i++){
g<<a[i]<<' ';
}
return 0;
}