Cod sursa(job #2675055)

Utilizator George_CristianGeorge Dan-Cristian George_Cristian Data 21 noiembrie 2020 09:44:32
Problema Potrivirea sirurilor Scor 80
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.47 kb
#include <fstream>
#include <cstring>

using namespace std;

ifstream f("strmatch.in");
ofstream g("strmatch.out");

char a[2000005], b[2000005];
int poz[2000005], ind;

int main() {
    f.getline(a, 2000005);
    f.getline(b, 2000005);
    char *p = strstr(b, a);
    while (p) {
        poz[ind++] = p - b;
        p = strstr(p + 1, a);
    }
    g << ind << '\n';
    int stop = ind < 1000 ? ind : 1000;
    for (int i = 0; i < stop; ++i)
        g << poz[i] << ' ';
    return 0;
}