Cod sursa(job #22040)

Utilizator robbyRobertino robert robby Data 25 februarie 2007 14:59:58
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <stdio.h>
#include <string.h>
#include <math.h>
char s[102];
int a[101];
FILE *f,*g;
int main()
{
  int i,j,t,nr,p,k;
  long x,y;
  f=fopen("cifra.in","rt");
  g=fopen("cifra.out","wt");
  fscanf(f,"%d\n",&t);
  fprintf(stdout,"\n");
  y=0;
  for (i=1;i<=99;i++)
	{
	  j=i%10;
	  nr=(i-1)%4;
	  nr++;
	  x=pow(j,nr);
	  x=x%10;
	  y+=x;
	  a[i]=y%10;
	}

for (k=1;k<=t;k++)
{
  fgets(s,103,f);
  nr=strlen(s)-2;
  if (nr)
	p=(s[nr-1]-'0')*10+(s[nr]-'0');
   else
	 p=s[nr]-'0';
  fprintf(g,"%d\n",a[p]);
}
  fclose(f);
  fclose(g);
  return 0;
}