Cod sursa(job #899824)

Utilizator vgabi94Vaduva Gabriel vgabi94 Data 28 februarie 2013 16:33:20
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <string>
#include <ctime>
#include <cstdio>
using namespace std;
// Solutie folosind find din tipul string
unsigned pos[1001]; int k;
char a[2000002], b[2000002];
int main()
{
    freopen("strmatch.in","r",stdin);
    freopen("strmatch.out","w",stdout);

    gets(a);
    gets(b);

    string A(a), B(b);

    unsigned found = B.find(A, 0);
    while (found != string::npos)
    {
        k++;
        if (k <= 1000) pos[k] = found;
        found++;
        found = B.find(A, found);
    }
    printf ("%d\n", k);
    int min = k <= 1000 ? k : 1000;
    for (int i = 1; i <= min; i++) printf ("%d ", pos[i]);
    return 0;
}