Pagini recente » Profil Vlad3108 | Monitorul de evaluare | Cod sursa (job #712928) | fmi-no-stress-3/solutii | Cod sursa (job #1996784)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cifra(int x, int p)
{
if(x==0||x==1||x==5||x==6)
return x;
if(x==2)
if(p%4==1)
return 2;
else
if (p%4==2)
return 4;
else
if(p%4==3)
return 8;
else
return 6;
if(x==3)
if(p%4==1)
return 3;
else
if (p%4==2)
return 9;
else
if(p%4==3)
return 7;
else
return 1;
if(x==4)
if(p%2==1)
return 4;
else
return 6;
if(x==7)
if(p%4==1)
return 7;
else
if (p%4==2)
return 9;
else
if(p%4==3)
return 3;
else
return 1;
if(x==8)
if(p%4==1)
return 8;
else
if (p%4==2)
return 4;
else
if(p%4==3)
return 2;
else
return 6;
if(x==9)
if(p%2==1)
return 9;
else
return 1;
}
void scadere_1(char a[]){
int n = strlen(a), i=0, x=0;
char c[1001];
strrev(a);
while(x<10){
x = a[i] - '0' -1 + 10 ;
a[i] = x%10 + '0';
i++;
}
strrev(a);
while(a[0]=='0'){
strcpy(a,a+1);
}
if(a[0]==NULL)
a[0]='0';
}
int main()
{
int t,i,s,c,p;
char n[10001];
freopen("cifra.in","r",stdin);
freopen("cifra.out","w",stdout);
scanf("%d%c",&t);
for(i = 1 ; i <= t ; i++){
gets(n);
s=0;
while(strcmp(n,"0")){
c = n[strlen(n)-1]-'0';
if(strlen(n)> 1)
p = (n[strlen(n)-2]-'0')*10+c;
else p = c;
s = (s + cifra(c,p))%10;
scadere_1(n);
}
printf("%d\n",s);
}
return 0;
}