Cod sursa(job #997354)

Utilizator StanAndreiAndrei Stan StanAndrei Data 13 septembrie 2013 21:21:39
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <stdio.h>
#include <string.h>

using namespace std;

char S[110];
int N,T,L[101];

int main()
{
    freopen ("cifra.in","r",stdin);
    freopen ("cifra.out","w",stdout);

    int i,j,x;
    for (i=1;i<=100;i++)
    {
        x=1;
        for (j=1;j<=i;j++)
            x=x*i%10;
        L[i]=(L[i-1]+x)%10;
    }

    scanf("%d\n",&T);
    for (i=1;i<=T;i++)
    {
        scanf("%s",S);
        x=strlen(S);
        if (x==1) printf("%d\n",L[S[0]-'0']);
        else printf("%d\n",L[(S[x-2]-'0')*10+(S[x-1]-'0')]);
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}