Cod sursa(job #523201)

Utilizator SadmannCornigeanu Calin Sadmann Data 17 ianuarie 2011 13:52:26
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.2 kb
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
FILE *in,*out;
int T,j,q,S;
char N[100],rep[100];
double nr_rep;

int main()
{
	in=fopen("cifra.in","rt");
	out=fopen("cifra.out","wt");
	fscanf(in,"%d",&T);
	for(q=1;q<=T;q++)
	{
		S=0;
		fscanf(in,"%s",N);
		strcpy(rep,N);
		rep[strlen(rep)-1]=NULL;
		//nr_rep=atoi(rep);
		S=(atoi(rep)*(1+6+5+6+9))%10;		
		if( (rep[strlen(rep)-1]-48)%2==0)
			S+= ( (atoi(rep)/2)*(3+7+4+6+3+7+6+4) )%10;
		else
		{
			if(atoi(rep)!=1)
				S+= ( (atoi(rep)/2+1)*(3+4+3+6) + ( atoi(rep)/2)*(7+6+7+4) )%10;
			else
				S+=(7+4+3+6);
		}
				
		j=N[strlen(N)-1]-48;
		if(j)
		{
			if(j==1)
				S+=1;
			if(j==2)
			{
				if( (rep[strlen(rep)-1]-48)%2==0 )
					S+=4;
				else
					S+=6;
			}
			if(j==3)
			{
				if( (rep[strlen(rep)-1]-48)%2==0 )
					S+=3;
				else
					S+=7;
			}
			if(j==4)
				S+=6;
			if(j==5)
				S+=5;
			if(j==6)
				S+=6;
			if(j==7)
			{
				if( (rep[strlen(rep)-1]-48)%2==0 )
					S+=3;
				else
					S+=7;
			}
			if(j==8)
			{
				if( (rep[strlen(rep)-1]-48)%2==0 )
					S+=6;
				else
					S+=4;
			}
			if(j==9)
				S+=9;
		}
		fprintf(out,"%d\n",S%10);
	}
	
	
	
	return 0;
}