Pagini recente » Cod sursa (job #1221082) | Cod sursa (job #847505) | Cod sursa (job #1022675) | Cod sursa (job #2527451) | Cod sursa (job #523599)
Cod sursa(job #523599)
#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);
if(strlen(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(rep[strlen(rep)-1]!='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)
{
bool ok=true;
if(strlen(rep) && !((rep[strlen(rep)-1]-48)%2) )
ok=false;
if(j==1)
S++;
if(j==2)
{
S++;
if(ok)
S+=4;
else
S+=6;
}
if(j==3)
{
S++;
if(ok)
S+=11;
else
S+=9;
}
if(j==4)
{
S++;
S+=6;
if(ok)
S+=11;
else
S+=9;
}
if(j==5)
{
S++;
S+=6;
S+=5;
if(ok)
S+=11;
else
S+=9;
}
if(j==6)
{
S++;
S+=6;
S+=5;
S+=6;
if(ok)
S+=11;
else
S+=9;
}
if(j==7)
{
S++;
S+=6;
S+=5;
S+=6;
if(ok)
S+=14;
else
S+=16;
}
if(j==8)
{
S++;
S+=6;
S+=5;
S+=6;
if(ok)
S+=20;
else
S+=20;
}
if(j==9)
{
S++;
S+=6;
S+=5;
S+=6;
S+=9;
if(ok)
S+=20;
else
S+=20;
}
}
fprintf(out,"%d\n",S%10);
}
return 0;
}