Cod sursa(job #1060982)

Utilizator alex_HarryBabalau Alexandru alex_Harry Data 18 decembrie 2013 23:30:19
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.33 kb
#include <fstream>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int LastDig[105];
int number;
inline int Last(int x)
{
    if(x%10==1)
        return 1;
    if(x%10==2)
    {
        if(x%4==2)
            return 4;
        else
            return 6;
    }
    if(x%10==3)
    {
        if(x%4==1)
            return 3;
        else
            return 7;
    }
    if(x%10==4)
    {
        if(x%2==0)
            return 6;
        else
            return 4;
    }
    if(x%10==5)
        return 5;
    if(x%10==6)
        return 6;
    if(x%10==7)
    {
        if(x%4==1)
            return 7;
        if(x%4==3)
            return 3;
    }
    if(x%10==8)
    {
        if(x%4==2)
            return 4;
        else
            return 6;
    }
    if(x%10==9)
    {
        if(x%2==1)
            return 9;
        else
            return 1;
    }
    if(x%10==0)
        return 0;
}
void Precalc()
{
    int i;
    for(i=1;i<=100;i++)
        LastDig[i]=(LastDig[i-1]+Last(i))%10;
}
int main()
{
    int T;
    f>>T;
    Precalc();
    while(T--)
    {
        char dig1='0',dig2='0';
        char ch;
        f>>ch;
        dig2=dig1;
        dig1=ch;
        number=(dig2-'0')*10+dig1-'0';
        g<<LastDig[number]<<"\n";
    }
    return 0;
}