Cod sursa(job #2979118)

Utilizator bogdan_raul55Bogdan Raul bogdan_raul55 Data 14 februarie 2023 19:41:12
Problema Potrivirea sirurilor Scor 80
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <fstream>
#include <string.h>
using namespace std;

ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
char z[16];
int x,y;
char a[2000002];
char b[2000002];
int c[2000002];
int nr = 0;
int main()
{
    fin >> a >> b;
    x = strlen(a);
    y = strlen(b);
    for(int i = 0; i+x-1 <= y-1; i++){
        bool ok = true;
        for(int j = 0; j <= x-1; j++){
            if(a[j] != b[i+j]){
                ok = false;
                break;
            }
        }
        if(ok){ 
            nr++;
            c[nr] = i;
        }
    }
    fout << nr << "\n";
    for(int i = 1; i <= nr && i <= 1000; i++){
        fout << c[i] << " ";
    }
    return 0;
}