Cod sursa(job #2847097)
Utilizator | Dobra Emilia Emilia23 | Data | 10 februarie 2022 11:06:02 |
---|---|---|---|
Problema | Potrivirea sirurilor | Scor | 40 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
//KMP
#include <bits/stdc++.h>
using namespace std;
ifstream f("strmatch.in");
ofstream g("strmatch.out");
const int SIZE = 2000005;
char s1[SIZE],s2[SIZE],*p;
int sol[SIZE],cnt;
int main()
{
f>>s1>>s2;
p=strstr(s2,s1);
while(p)
{
cnt++;
sol[cnt]=p-s2;
p=strstr(p+1,s1);
}
g<<cnt<<'\n';
for(int i=1;i<=cnt;i++)g<<sol[i]<<' ';
}