Cod sursa(job #2905651)

Utilizator alexdvResiga Alexandru alexdv Data 22 mai 2022 21:40:40
Problema Potrivirea sirurilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;

char A[2000001], B[2000001];
int v[1000], pos = 0, times = 0;

int main() {
    ifstream fin("strmatch.in");
    ofstream fout("strmatch.out");
    fin >> A;
    fin >> B;
    char *p = strstr(B, A);
    while (p != 0) {
        ++times;
        ++pos;
        v[pos] = p  - B;
        p = strstr(p + 1, A);
    }
    fout << times << '\n';
    for (int i = 1; i <= pos; ++i) {
        fout << v[i] << ' ';
    }
    return 0;
}