Cod sursa(job #1551560)

Utilizator Vlad_317Vlad Panait Vlad_317 Data 16 decembrie 2015 00:15:49
Problema Potrivirea sirurilor Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include <stdio.h>
#include <string.h>

using namespace std;

char a[2000005], b[2000005];
int sol[100005], nr = 0;

int main()
{
    FILE *fin, *fout;

    fin = fopen("strmatch.in", "r");
    fout = fopen("strmatch.out", "w");

    int l;

    fgets(a, 2000003, fin);
    l = strlen(a);
    a[l - 1] = NULL;
    fgets(b, 2000003, fin);
    l = strlen(b);
    b[l - 1] = NULL;

    char * poz = strstr(b, a);
    while(poz != NULL)
    {
        int p = poz - b;
        sol[++nr] = p;
        poz = strstr(b + p + 1, a);
    }

    int x = nr;

    if(nr > 1000)
        x = 1000;

    fprintf(fout, "%d\n", nr);

    for(int i = 1; i <= x; i++)
    {
        fprintf(fout, "%d ", sol[i]);
    }

    fprintf(fout, "\n");

    return 0;
}