Cod sursa(job #1457402)

Utilizator vlad6001Pintilie Vlad vlad6001 Data 3 iulie 2015 12:28:35
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.49 kb
#include <fstream>
using namespace std;

ifstream fin("cifra.in");
ofstream fout("cifra.out");

int nr, i, x, v[200], total, numar;
char c;

int main()
{
    fin >> numar;
    fin.get();
    for(i=1; i <= numar; i++)
    {
        fin.get(c);
        x = 1;
        while(c != '\n')
        {
            v[x] = c-'0';
            x++;
            fin.get(c);
        }
        x--;

        nr = v[x-1]*10 + v[x];

        total = (nr / 10) * 47;
        nr %= 10;

        if(v[x-1] % 2 == 0)
        {
            if(nr >= 1)
            total += 1;
            if(nr >= 2)
            total += 4;
            if(nr >= 3)
            total += 7;
            if(nr >= 4)
            total += 6;
            if(nr >= 5)
            total += 5;
            if(nr >= 6)
            total += 6;
            if(nr >= 7)
            total += 3;
            if(nr >= 8)
            total += 6;
            if(nr >= 9)
            total += 9;
        }
        else
        {
            if(nr >= 1)
            total += 1;
            if(nr >= 2)
            total += 6;
            if(nr >= 3)
            total += 3;
            if(nr >= 4)
            total += 6;
            if(nr >= 5)
            total += 5;
            if(nr >= 6)
            total += 6;
            if(nr >= 7)
            total += 7;
            if(nr >= 8)
            total += 4;
            if(nr >= 9)
            total += 9;
        }
        fout << total%10 << '\n';
    }
}