Cod sursa(job #101817)

Utilizator DjSefuWrong name DjSefu Data 13 noiembrie 2007 21:04:49
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include<stdio.h>
#include<string.h>
FILE *f=fopen("cifra.in","r"),
     *g=fopen("cifra.out","w");
int c[10][4],sum,n,i,t,j;
char s[103];
int main()
{ c[1][0]=c[1][1]=c[1][2]=c[1][3]=1;
  c[2][0]=6;
  c[2][1]=2;
  c[2][2]=4;
  c[2][3]=8;
  c[3][0]=1;
  c[3][1]=3;
  c[3][2]=9;
  c[3][3]=7;
  c[4][0]=6;
  c[4][1]=4;
  c[4][2]=6;
  c[4][3]=4;
  c[5][0]=c[5][1]=c[5][2]=c[5][3]=5;
  c[6][0]=c[6][1]=c[6][2]=c[6][3]=6;
  c[7][0]=1;
  c[7][1]=7;
  c[7][2]=9;
  c[7][3]=3;
  c[8][0]=6;
  c[8][1]=8;
  c[8][2]=4;
  c[8][3]=2;
  c[9][0]=c[9][2]=1;
  c[9][1]=c[9][3]=9;
  fscanf(f,"%d",&t);
  for(j=1;j<=t;++j) { fscanf(f,"%s",&s);
		      n=s[strlen(s)-1]-'0';
		      if(strlen(s)>1) n+=(s[strlen(s)-2]-'0')*10;
		      sum=0;
		      for(i=1;i<=n;++i)
			 sum+=c[i%10][i%10%4];
		      sum%=10;
		      fprintf(g,"%d\n",sum);
		    }
  fclose(f);
  fclose(g);
  return 0;
}