Cod sursa(job #1524695)

Utilizator VladCiofuCiofu Vlad VladCiofu Data 14 noiembrie 2015 12:55:13
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <iostream>
#include <string.h>

using namespace std;

int f[10];

int ft[10];

void cl(int x[])
{
    for(int i = 0; i < 10; i++) x[i] = 0;
}

bool check()
{
    for(int i = 0; i < 10; i++)
    {
        while(i == 2 || i == 5 || i == 6 || i == 9) i++;

        if(f[i] < ft[i]) return false;
    }

    if(ft[2] + ft[5] > f[2] + f[5]) return false;
    if(ft[6] + ft[9] > f[6] + f[9]) return false;

    return true;
}

int main()
{
    int t;

    while(cin >> t)
    {
        cl(f);

        cl(ft);

        cin.get();

        char s[201];

        cin.getline(s, 201);

        for(int i = 0; i < strlen(s); i++) f[s[i] - '0']++;

        int nr = 1, t1 = t;

        while(t != 0)
        {
            ft[t%10]++;

            t /= 10;
        }

        if(check())
        {
            while(t1 != 0)
            {
                int c = t1 % 10;
                t1 /= 10;

                if(c == 2 || c == 5)
                {
                    if(f[2] != 0 && f[5] != 0)
                    {
                        f[2]--;
                        f[5]--;
                        nr *= 2;
                    }
                }
                else if(c == 6 || c == 9)
                {
                    if(f[6] != 0 && f[9] != 0)
                    {
                        f[6]--;
                        f[9]--;
                        nr *= 2;
                    }
                }
            }

            cout << nr << endl;
        }
        else cout << 0 << endl;
    }
}