Cod sursa(job #1714175)

Utilizator comandantul_bCapitanul Burcea comandantul_b Data 7 iunie 2016 18:28:18
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <cstdio>
#include <cstring>
#define NMax 105

char s[NMax];
int ans[NMax];

void precalc()
{
    int i,x,s;
    for( i = 1; i <= 99; ++i )
    {
        x = i % 10;

        //
        if( i % 4 == 0 )
        s = x * x * x * x;
        else if( i % 4 == 1 )
        s = x;
        else if( i % 4 == 2 )
        s = x * x;
        else s = x * x * x;

    s = s % 10;
    ans[i] = ( ans[i-1] + s ) % 10 ;
    }
}


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

    int i,T,n,value;
    char pass;

    precalc();

    scanf("%d",&T);
    scanf("%c",&pass);

    while(T)
    {
        fgets(s,NMax,stdin);
        n = strlen(s);
        if( s[n-1] == '\n' ) n--;

        if(n>1)
            value = ( s[n-2] - '0' ) *10 + s[n-1] - '0' ;
        else
            value = s[n-1] - '0';

        printf("%d\n",ans[value]);

        T--;
    }



    return 0;
}