Pagini recente » Cod sursa (job #211326) | Cod sursa (job #392664) | Cod sursa (job #306582) | Cod sursa (job #334547) | Cod sursa (job #3038861)
#include <iostream>
#include <fstream>
#include <vector>
int main() {
std::ifstream input("strmatch.in");
std::ofstream output("strmatch.out");
std::string a, b;
input >> a >> b;
std::vector<int> ans;
auto hasher = std::hash<std::string>();
size_t a_hash = hasher(a);
std::string window = b.substr(0, a.length());
if (hasher(window) == a_hash) ans.push_back(0);
int len = a.length();
for (int i = 1; i + len - 1 < b.length(); ++i) {
window = window.substr(1);
window += b[len + i - 1];
if (hasher(window) == a_hash) ans.push_back(i);
}
output << ans.size() << '\n';
for (auto &x: ans) output << x << " ";
return 0;
}