Cod sursa(job #2483274)

Utilizator richardbaczur1Baczur Richard richardbaczur1 Data 29 octombrie 2019 17:08:29
Problema Potrivirea sirurilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.97 kb
#include <bits/stdc++.h>
#define NMAX 2000000
#define inFile "strmatch.in"
#define outFile "strmatch.out"

using namespace std;
char a[NMAX],b[NMAX];
int i;
queue<int> rez;
int main()
{
    freopen(inFile, "r", stdin);
    freopen(outFile, "w", stdout);

    scanf("%s", &a);
    scanf("%s", &b);
    bool isGood=false;
    for (i = 0; i < strlen(b); i++)
    {
        if (b[i] == a[0])
        {
            isGood = true;
            int j=1,x=i+1;
            while (j<strlen(a))
            {
                if (b[x]!=a[j])
                {
                    isGood = false;
                    break;
                }
                x++;
                j++;
            }
            if (isGood) rez.push(i);
        }

    }
    printf("%d \n", rez.size());
    for (int i=0;i<1000 && !rez.empty(); i++)
    {
        printf("%d ", rez.front());
        rez.pop();
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}