Cod sursa(job #1725017)

Utilizator danstefanDamian Dan Stefan danstefan Data 4 iulie 2016 18:47:28
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <bits/stdc++.h>
using namespace std;
int i,n,lu,c,s,r,nr;
char st[110];
int main()
{
    freopen("cifra.in","r",stdin);
    freopen("cifra.out","w",stdout);
    scanf("%d",&n);
    for(i=1; i<=n; ++i)
    {
        scanf("%s",&st);
        lu=strlen(st);
        c=st[lu-1]-'0';
        if(lu>=2)nr=(st[lu-2]-'0')*10+c;
        else nr=c;
        r=nr%4;
        if(r==2)c=c*c%10;
        else if(r==3)c=c*c*c%10;
        else if(r==0)c=c*c*c*c%10;
        s+=c;
        s%=10;
        printf("%d\n",s);
    }
    return 0;
}