Pagini recente » Cod sursa (job #837914) | Cod sursa (job #1142986) | Cod sursa (job #1633720) | Cod sursa (job #1183691) | Cod sursa (job #1983334)
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define PI 3.141592653589793;
using namespace std;
int main() {
freopen("strmatch.in", "r", stdin);
freopen("strmatch.out", "w", stdout);
string a, b;
getline(cin, a);
getline(cin, b);
vector<int> lps(a.size(), 0);
vector<int> result;
int ind = 0, i = 1, j = 0;
while(i < a.size()){
if(a[i] == a[ind]){
lps[i] = ind + 1;
i++;
ind++;
} else if(ind){
ind = lps[ind - 1];
} else {
i++;
}
}
i = 0;
while(i < b.size()){
if(b[i] == a[j]) {
i++;
j++;
} else if(j){
j = lps[j - 1];
} else {
i++;
}
if(j == a.size()){
result.pb(i - a.size());
j = lps[j-1];
}
}
printf("%d\n", result.size());
for(int i=0; i < result.size(); i++)
printf("%d ", result[i]);
}