Cod sursa(job #912851)

Utilizator BlackLordFMI Alex Oprea BlackLord Data 12 martie 2013 20:42:19
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>
#include <string.h>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int v[21]={0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4, 4};
int t, l, u, z, nr, i;
char s[110];
int main(){
    f>>t;
    for(i=1; i<=t; i++)
    {
        f.get();
        f.get(s, 110);
        l=strlen(s);
        u=s[l-1]-'0';
        z=s[l-2]-'0';
        if(strlen(s)==1 && u==0)
        {
            g<<"0\n";
            continue;
        }
        if(z>=0)
            nr=10*z+u;
        else
            nr=u;
        z=nr/20;
        u=nr%20;
        if(z==0)
            g<<v[nr]<<"\n";
        else
            g<<(z*v[20]+v[u])%10<<"\n";
    }
    return 0;
}