Cod sursa(job #126720)

Utilizator radamiRadu Patulescu radami Data 22 ianuarie 2008 18:44:23
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <stdio.h>
#include <string.h>

int n,v[120],s[120];

int putere(int a,int b)
{
	int k = 1;
	for (int i = 1;i <= b; ++i)
		k *= a;
	return k;
}


int main ()
{
	freopen("cifra.in","r",stdin);
	freopen("cifra.out","w",stdout);
	int k;
	s[0] = 0;
	s[1] = 1;
	for (int i = 2;i <= 99; ++i)
	{
		if (i % 4 != 0)
			k = putere (i%10,i%4);
			//k = pow(i%10,i%4);
		else
			k = putere(i%10,4);
		//	k = pow(i%10,4);
		s[i] = (s[i-1] + k)  % 10;
	}
	char aux[120];
	int l;
	//int cif1,cif2;
	scanf("%d",&n);
	//scanf("%c",&aux);
		gets(aux);
	for (int i = 1;i <= n; ++i)
	{	
		gets(aux);
		/*cif1 = 0;cif2= 0;
		scanf("%c",&aux);
	
		/while (aux != '\n' && aux != 26)
		{
			cif1 = cif2;
			cif2 = aux - 48;
			scanf("%c",&aux);
		}
		*/
		l = strlen(aux);
		if (l > 1)
			printf("%d\n",s[(aux[l-2] - 48) * 10 + aux[l-1] - 48]);
		else
			printf("%d\n",s[aux[l-1] - 48]);
		
	}
	
	
	
	return 0;
}