Pagini recente » Cod sursa (job #2253567) | Cod sursa (job #2197672) | Cod sursa (job #605525) | Cod sursa (job #211919) | Cod sursa (job #157231)
Cod sursa(job #157231)
#include<stdio.h>
#include<stdlib.h>
int main(){
FILE *fin=fopen("cifra.in","r");
FILE *fout=fopen("cifra.out","w");
int T,twostate,i,j,ucif,pucif;
char chb,chf,nch;
fscanf(fin,"%d\n",&T);
for(j=0;j<T;j++){
i=0;
nch='z';chb='z';chf='z';
while(nch!='\n'){
fscanf(fin,"%c",&nch);
if(nch!='\n'){
chb=chf;chf=nch;
}
i++;
}
pucif=atoi(&chb);
ucif=atoi(&chf)/10;
twostate=pucif*10+2;
twostate=(twostate%4==0)?6:4;
pucif*=7;pucif%=10;
switch(ucif){
case 1:pucif++;break;
case 2:pucif+=twostate+1;break;
case 3:pucif+=twostate+8;break;
case 4:pucif+=twostate+4;break;
case 5:pucif+=twostate+9;break;
case 6:pucif+=twostate+5;break;
case 7:pucif+=twostate+8;break;
case 8:pucif+=8;break;
case 9:pucif+=7;break;
}
fprintf(fout,"%d\n",pucif%10);
}
fclose(fin);
fclose(fout);
return 0;
}