Cod sursa(job #2402635)

Utilizator WladDalwMvladutu cristian vlad WladDalwM Data 10 aprilie 2019 21:06:34
Problema Potrivirea sirurilor Scor 14
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.32 kb
#include <fstream>

using namespace std;
ifstream cin("strmatch.in");
ofstream cout("strmatch.out");
int rez[2000001];
int main()
{

    long long a = 0 , mod = 999999999999989 , i;
    long long b = 0 , cif = 0 , cnt = 0 , p10 = 1 , poz = 1;
    char  k;
    cin.get(k);
    while(k != '\n')
    {
        if(k <= '9')
        a += (k - '0' + 53);
        else
        if(k >='a')
        a += (k - 'a' + 27);
        else
        a += (k - 'A' + 1);
        a *= 69;
        a = a % mod;
        cif++;
        p10 *= 69;
        cin.get(k);

    }
    a /= 69;
    p10 /= 69;
    while(cin.get(k) && cif)
    {
        cif--;
        if(k <= '9')
        b += (k - '0' + 53);
        else
        if(k >='a')
        b += (k - 'a' + 27);
        else
        b += (k - 'A' + 1);
        b *= 69;
        b %= mod;
    }
    b/= 69;
    if(b == a)
    {cnt++;
    rez[cnt] = poz;}
    while(cin.get(k))
    {
        poz++;
        b %= p10;
        b *= 69;

        if(k <= '9')
        b += (k - '0' + 53);
        else
        if(k >='a')
        b += (k - 'a' + 27);
        else
        b += (k - 'A' + 1);
        if(a == b)
        {cnt++;
        rez[cnt] = poz;}
    }
    cout << cnt << '\n';
    for(i = 1; i <= cnt; i++)
    cout << rez[i] << " ";
    return 0;
}