Cod sursa(job #424314)

Utilizator cristiprgPrigoana Cristian cristiprg Data 24 martie 2010 19:17:50
Problema Potrivirea sirurilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define DIM 2000005

char word[DIM], text[DIM];

int main()
{
    FILE *f = fopen("strmatch.in", "r");


    fscanf(f, "%s%s", word, text);


    puts(word);
    puts(text);
    fclose(f);

    char *F1 = word, *L1 = word+strlen(word)-1, *F2 = text, *L2 = text+strlen(text), *p = NULL;
    int c = 0;
    vector<int> ANS;
    ANS.reserve(1005);



    while((p = search(F2, L2, F1, L1)))
    {
 //       cout<<p;
        ++c;
        F2 = p;
        if (c <= 1000)
            ANS.push_back(p-F2);
    }
    f = fopen("strmatch.out", "w");
    fprintf(f, "%d\n", c);
    for (vector<int>::iterator it = ANS.begin(); it != ANS.end(); ++it)
        fprintf(f, "%d ", *it);
    fprintf(f, "\n");
    fclose(f);
    return 0;
}