Pagini recente » Cod sursa (job #3168954) | Cod sursa (job #442275) | Cod sursa (job #2386313) | Cod sursa (job #1916747) | Cod sursa (job #936437)
Cod sursa(job #936437)
#include <fstream>
#include <vector>
using namespace std;
int main() {
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
string word;
fin >> word;
int length = word.size();
int a[length];
int b;
a[0] = -1;
for (int i = 1; i < length; ++i) {
b = a[i-1];
while (b != -1 && word[b+1] != word[i]) b = a[b];
++b;
a[i] = word[b] == word[i]? b : -1;
}
vector<int> ans;
b = -1;
--length;
char c;
for (int i = 0; fin >> c; ++i) {
while (b != -1 && word[b+1] != c) b = a[b];
if (word[b+1] == c) ++b;
if (b == length) ans.push_back(i-length);
}
fout << ans.size() << '\n';
for (vector<int>::iterator it = ans.begin(); it != ans.end(); ++it)
fout << *it << ' ';
return 0;
}