Pagini recente » Cod sursa (job #564304) | Cod sursa (job #1967622) | Cod sursa (job #554211) | Cod sursa (job #912291) | Cod sursa (job #523573)
Cod sursa(job #523573)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
FILE *in,*out;
int T,j,q;
char N[100],rep[100];
int S;
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= (rep[strlen(rep)-1]-48) * ((1+6+5+6+9)%10);
if( (rep[strlen(rep)-1]-48)%2==0)
S+= ( ((rep[strlen(rep)-1]-48)/2)* ((3+7+4+6+3+7+6+4)%10) )%10;
else
{
if(atoi(rep)!=1)
S+= ( ((rep[strlen(rep)-1]-48)/2+1)*((3+4+3+6)%10) + ( (rep[strlen(rep)-1]-48)/2)*((7+6+7+4)%10) )%10;
else
S+=(7+4+3+6)%10;
}
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;
}