Pagini recente » Cod sursa (job #2364479) | Rating Negrea Dumitru Marian (Marian1998) | Cod sursa (job #1117368) | Cod sursa (job #69433) | Cod sursa (job #1467835)
#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;
getline(f,m);getline(f,n);
tr1 ::hash<string> hsh;
long long q=hsh(m);v=m.length();r=n.length();
for (int i=0;i<=r-v;i++){
if (q==hsh(n.substr(i,v))){
for (int j=0;j<v;j++){
if (m[j]==n[i+j]) ++t;
if (t==v) {a.push_back(i);t=0;++x;}
}
}
}
g<<x<<'\n';
for (int i=0;i<x;i++){
g<<a[i]<<' ';
}
return 0;
}