Cod sursa(job #1004829)

Utilizator alex-florinHarbuzariu Alexandru Florin alex-florin Data 3 octombrie 2013 18:23:47
Problema Cifra Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <fstream>
#include <string.h>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int a, tab[200];
void numar(char f)
{
    if(f=='0') tab[a++]=0;
    else if(f=='1') tab[a++]=1;
    else if(f=='2') tab[a++]=2;
    else if(f=='3') tab[a++]=3;
    else if(f=='4') tab[a++]=4;
    else if(f=='5') tab[a++]=5;
    else if(f=='6') tab[a++]=6;
    else if(f=='7') tab[a++]=7;
    else if(f=='8') tab[a++]=8;
    else tab[a++]=9;
}
int main()
{
    char n[105];
    const int suma[22]={0,1,5,2,8,3,9,2,8,7,7,8,4,7,3,8,4,1,5,4,4};
    int x, j, t, i, cat, rest, k;
    f>>t;
    for(i=1; i<=t; i++)
    {
        cat=0, rest=0, k=0, a=0;
        f>>n;
        x=strlen(n); j=0;
        while(j!=x)
            numar(n[j++]);
        if(tab[x-2]%2!=0)
            rest=10;
        rest=rest+tab[x-1];
        j=0;
        while(k/20==0)
        k=k*10+tab[j++];
        while(j<=x)
        {
            cat=k/20;
            k=(k-cat*20)*10+tab[j];
            j++;
        }
        g<<(suma[rest]+cat*4)%10<<endl;
    }
    f.close();
    g.close();
    return 0;
}