Pagini recente » Cod sursa (job #1808848) | Cod sursa (job #2098623) | Cod sursa (job #1815213) | Cod sursa (job #1693649) | Cod sursa (job #2391606)
#include <fstream>
#include <vector>
#include <string>
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
vector<int> matches;
string a, b;
bool Check_Match(int j) {
for (int i = 0; i < a.size(); ++i) {
if (a[i] != b[j++]) {
return false;
}
}
return true;
}
void Try_Match(int j) {
if (Check_Match(j)) {
matches.push_back(j);
}
}
int main() {
getline(fin, a);
getline(fin, b);
int n = b.size() - a.size() + 1;
long long s = 0, z = 0;
for (int i = 0; i < a.size(); ++i) {
s += int(a[i]);
z += int(b[i]);
}
for (int i = 1, j = a.size(); i < n; ++i) {
z = z - int(b[i - 1]) + int(b[j++]);
if (z == s) {
Try_Match(i);
}
}
fout << matches.size() << "\n";
n = matches.size() < 1000 ? matches.size() : 1000;
for (int i = 0; i < n; ++i) {
fout << matches[i] << " ";
}
}