Cod sursa(job #45301)

Utilizator xdanxDaN xdanx Data 1 aprilie 2007 13:04:55
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<stdio.h>
#include<math.h>
#include<string.h>
int uc(int a,int ex)
{
	a%=10;
	ex%=10;
	if (ex%4==0) 
		return (int)pow(a,4)%10; 
	ex%=4;
	return (int)pow(a,ex)%10;
}
int main()
{
	char m[120];
	FILE *in=fopen("cifra.in","r"),*out=fopen("cifra.out","w");
	int n,s,t,j,c;
	fscanf(in,"%d",&t);
	for (int i=0;i<t;++i)
	{
		s=0;
		fscanf(in,"%s",m);
		printf("M este %s\n",m);
		n=(m[strlen(m)-2]-'0')*10+(m[strlen(m)-1]-'0');
		printf("Iltimele 2 cifre = %d \n",n);
		n%=100;
		c=n/20;
		s+=c*5;
		//uc=n%20;
		for (j=1;j<=n%20;++j)
			{
				printf("Uc pentru %d este %d\n",j,uc(j,j));
				s+=uc(j,j);
			}
		fprintf(out,"%d\n",s%10);
	}
	return 0;
}