Cod sursa(job #1219454)

Utilizator andru47Stefanescu Andru andru47 Data 14 august 2014 11:22:04
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <cstdio>
#include <cstring>
using namespace std;
int i,j,poz,N,v[1500];
char s1[2000001],s2[2000001];
bool ok;
int main()
{
    freopen("strmatch.in","r",stdin);
    freopen("strmatch.out","w",stdout);
    gets(s1);
    gets(s2);
    for (i=0;i<strlen(s2);i++)
    {   poz=0;ok=false;
        for (j=i;j<=i+strlen(s1)-1;j++)
            if (s1[poz]!=s2[j]){ok=true;break;}
                    else poz++;
        if (ok==false&&N<=1000)v[++N]=i;
        else if (ok==false&&N>1000)N++;
    }
    printf("%d\n",N);
    for (i=1;i<=1000;i++)
    {
        if (i>N)break;
        printf("%d ",v[i]);
    }
    return 0;
}