Cod sursa(job #1692108)

Utilizator PruteanuTheoPruteanu Theodor PruteanuTheo Data 20 aprilie 2016 09:59:52
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <cstdio>
#include <cstring>

using namespace std;

const int NMAX=100;

int v[NMAX];

char s[105];

int main()
{
    freopen("cifra.in","r",stdin);
    freopen("cifra.out","w",stdout);
    int i,exp,y,j,sol=0;
    for(y=1;y<=NMAX;++y)
    {
        i=y;
        exp=i%4;
        if(exp==0)
            exp=4;
        i=i%10;
        for(j=1;j<exp;++j)
            i=i*y;
        i=i%10;
        sol=sol+i;
        sol=sol%10;
        v[y]=sol;
    }
    int t,l,nr;
    scanf("%d\n",&t);
    for(i=1;i<=t;++i)
    {
        gets(s+1);
        l=strlen(s+1);
        scanf("\n");
        nr=0;
        if(l>1)
        {
        nr=nr+s[l-1]-'0';
        nr=nr*10;
        nr=nr+s[l]-'0';
        }
        else
        {
            nr=nr+s[l]-'0';
        }
        printf("%d",v[nr]);
        if(i!=t)
            printf("\n");
    }
    return 0;
}