Pagini recente » Cod sursa (job #47395) | Cod sursa (job #3244027) | Cod sursa (job #1434325) | Cod sursa (job #2763513) | Cod sursa (job #1833289)
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ifstream in("strmatch.in");
ofstream out("strmatch.out");
string needle, haystack;
in >> needle;
in >> haystack;
int pos = -1;
vector<int> matches;
do {
pos = haystack.find(needle, pos + 1);
if (pos != -1) {
matches.push_back(pos);
}
} while (pos != -1);
int toShow = min((int) matches.size(), 1000);
out << matches.size() << "\n";
for (int i = 0; i < toShow; i++) {
out << matches[i] << " ";
}
in.close();
out.close();
return 0;
}