Pagini recente » Statistici Craciun Radu (CraciunRadu) | Cod sursa (job #1896979) | Cod sursa (job #743091) | tema | Cod sursa (job #1579664)
// Problema Strmatch - InofArena ( www.infoarena.ro/problema/strmatch )
#include <cstdio>
#include <string>
#include <unordered_map>
#include <fstream>
#include <vector>
#define in "strmatch.in"
#define out "strmatch.out"
#define len 2000007
#define pb push_back
using namespace std;
ifstream cin(in);
ofstream cout(out);
int sze1, sze2, nrSol;
string str1, str2, tmp;
unordered_map <string, bool> RabinKarp;
vector <int> vecSol;
int main()
{
cin >> str1 >> str2;
sze1 = str1.size();
sze2 = str2.size();
RabinKarp[str1] = true;
for(int i = 0 ; i< sze2 - sze1 + 1; ++i)
{
tmp.replace(0, len, str2, i, sze1);
if(RabinKarp[tmp] == true)
{
nrSol ++;
vecSol.pb(i);
}
else
{
RabinKarp.erase(tmp);
}
}
cout << nrSol << "\n";
for(int i = 0; i< nrSol; ++i)
{
cout << vecSol[i] << " ";
}
cout << "\n";
}