Cod sursa(job #284757)

Utilizator shnakoVlad Schnakovszki shnako Data 21 martie 2009 22:42:48
Problema Cifra Scor 100
Compilator cpp Status done
Runda petru_toti Marime 0.64 kb
#include <stdio.h>
#include <string.h>
int t, a[20], x, k, i, y;
char v[102], c;
int main(void)
{
a[1]=1;a[2]=5;a[3]=2;a[4]=8;a[5]=3;a[6]=9;a[7]=2;a[8]=8;
a[9]=7;a[10]=7;a[11]=8;a[12]=4;a[13]=7;a[14]=3;a[15]=8;a[16]=4;
a[17]=1;a[18]=5;a[19]=4;a[0]=0;
freopen("cifra.in", "r", stdin);
freopen("cifra.out", "w", stdout);
scanf ("%d", &t);
scanf ("%c", &c);
for (i=1;i<=t;i++)
	{
   fgets(v, 102, stdin);
	k=strlen(v)-1;
	if (k==1)
      printf("%d\n", a[v[k-1]-48]);
   else
   	{
      y=(v[k-1]-48+10*(v[k-2]-48))/20;
   	x=(v[k-1]-48+10*(v[k-2]-48))%20;
      printf ("%d\n", (4*y+a[x])%10);
      }
   }
fcloseall();
return 0;
}