Pagini recente » Cod sursa (job #1346880) | Cod sursa (job #2669412) | Cod sursa (job #871172) | Cod sursa (job #1346960) | Cod sursa (job #2001333)
#include <iostream>
#include <fstream>
#include <stack>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <stack>
#include <cstring>
using namespace std;
ifstream in("strmatch.in");
ofstream out("strmatch.out");
#define ll long long
#define ull unsigned long long
#define pb push_back
const int inf = 1e9 + 5;
const int NMax = 2e6 + 5;
const int base = 73;
int N,M,nrSol;
int sol[NMax];
char patt[NMax],str[NMax];
int main() {
in>>(patt+1)>>(str+1);
N = strlen(patt+1);
M = strlen(str+1);
ull pattHash = 0,strHash = 0,pw = 1;
for (int i=1;i <= N;++i) {
pattHash = pattHash * base + patt[i] * base;
strHash = strHash * base + str[i] * base;
pw = pw * base;
}
if (pattHash == strHash) {
sol[++nrSol] = 0;
}
for (int i=N+1;i <= M;++i) {
strHash = (strHash - str[i-N] * pw) * base + str[i] * base;
if (pattHash == strHash) {
sol[++nrSol] = i - N;
}
}
out<<nrSol<<'\n';
int lim = min(1000,nrSol);
for (int i=1;i <= lim;++i) {
out<<sol[i]<<' ';
}
in.close();out.close();
return 0;
}