Cod sursa(job #2905652)

Utilizator alexdvResiga Alexandru alexdv Data 22 mai 2022 21:50:03
Problema Potrivirea sirurilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 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);
    if (p != 0) {
    	++times;
    }
    while (p != 0) {
        ++pos;
        v[pos] = p - B;
        p = strstr(p + 1, A);
        if (p != 0) {
        	++times;
        }
    }
    fout << times << '\n';
    for (int i = 1; i <= pos; ++i) {
        fout << v[i] << ' ';
    }
    return 0;
}