Cod sursa(job #1412461)

Utilizator teoceltareconstantin teodor teoceltare Data 1 aprilie 2015 12:10:19
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include<fstream>
#include<cstring>
using namespace std;
char a[2000010],b[2000010];
int v[1010],k;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
int main()
{
    int e=0;
    int nr,x=0,x1,nr1;
    fin.get(a,2000010);
    nr=strlen(a);
    while(fin)
    {
        x++;
        fin>>b[x];
        if(x>=nr)
        {
            e=1;
            x1=x;
            nr1=nr-1;
            while(e and nr1>=0)
            {
                if(a[nr1]==b[x1])
                {
                    nr1--;
                    x1--;
                }
                else e=0;
            }
            if(e==1)
            {
                k++;
                if(k<=1000)
                {
                    v[k]=x1;
                }
            }
        }
    }
    fout<<k<<'\n';
    for(int a1=1;a1<=k;a1++)
    {
        fout<<v[a1]<<" ";
    }
}