Cod sursa(job #3144681)
| Utilizator | Data | 9 august 2023 21:04:41 | |
|---|---|---|---|
| Problema | Potrivirea sirurilor | Scor | 38 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <fstream>
#include <vector>
using namespace std;
// https://infoarena.ro/problema/strmatch
ifstream f("strmatch.in");
ofstream g("strmatch.out");
int main(void) {
string a, b;
f >> a >> b;
const int sza = a.size(), szb = b.size();
int t = 0;
vector<int> res;
for (int i = 0; i < szb - sza; i++) {
if (b[i] == a[0]) {
string tmp = b.substr(i, sza);
if (tmp == a) {
t++;
res.push_back(i);
}
}
}
g << t << endl;
for (int r : res) g << r << " ";
return 0;
}