Cod sursa(job #1984574)

Utilizator Dragne.Andrei11Dragne Andrei Dragne.Andrei11 Data 25 mai 2017 11:18:05
Problema Potrivirea sirurilor Scor 14
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include <bits/stdc++.h>
#define nmax 2000001

using namespace std;

char a[nmax];
char b[nmax];
vector <int> afis;

bool verif(int poz, int la)
{
    if(la%2==0){
        for(int i=0;i<la/2;i++)
        {
            if(a[i]!=b[poz]||a[la-i-1]!=b[la+poz-i-1])
                return false;
        }
        return true;
    }
    else
    {
        for(int i=0;i<la/2;i++)
        {
            if(a[i]!=b[poz+i]||a[la-i-1]!=b[la+poz-i-1])
                return false;
        }
        if(a[la/2]!=b[poz+la/2])
            return false;
        return true;
    }
}

int main()
{
    freopen("strmatch.in", "r", stdin);
    freopen("strmatch.out", "w", stdout);
    int la, lb;

    gets(a);
    gets(b);
    la=strlen(a);
    lb=strlen(b);
    int n=0;
    for(int i=0;i<lb-la;i++)
    {
        if(verif(i, la)==true)
        {
            n++;
            if(n<1000)
                afis.push_back(i);
        }
    }
    printf("%d\n", n);
    for(int i=0;i<afis.size();i++)
        printf("%d ", afis[i]);
    printf("\n");

    return 0;
}