Cod sursa(job #2893027)

Utilizator alexdvResiga Alexandru alexdv Data 24 aprilie 2022 17:54:03
Problema Potrivirea sirurilor Scor 38
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
char A[2000000], B[2000000];

int main() {
	ifstream fin ("strmatch.in");
	ofstream fout ("strmatch.out");
	fin >> A;
	fin >> B;
	int start[20000], pos = 0, Alg = strlen(A), Blg = strlen(B), lg, k, total = 0;
	for (int i = 0; i < Blg; ++i) {
    if (B[i] == A[0]) {
      lg = 0, k = 0;
      int j = i;
      while (B[j] == A[k]) {
        ++lg;
        ++k;
        ++j;
      }
      if (lg == Alg) {
        start[pos] = i;
        ++pos;
        ++total;
      }
    }
	}
	fout << total << '\n';
	for (int i = 0; i < pos; ++i) {
    fout << start[i] << ' ';
	}
	return 0;
}