Pagini recente » Cod sursa (job #48464) | Cod sursa (job #1359176) | Cod sursa (job #191230) | Cod sursa (job #1348824) | Cod sursa (job #1599360)
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main() {
int t,len,rest,cat,ult_cif,aux;
char n[105];
int ult[20] = {0,1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4};
FILE *pFile,*oFile;
pFile = fopen ( "cifra.in" , "r" );
oFile = fopen ( "cifra.out" , "w" );
fscanf(pFile, "%d", &t);
fgets(n,10,pFile);
for(int i=0; i<t; i++) {
fgets(n, 105, pFile);
len = strlen(n)-1;
if( len == 1) {
aux = n[0]-'0';
ult_cif = ult[aux];
} else {
rest = 10*(n[0]-'0') + n[1]-'0';
cat = rest/20;
rest = rest%20;
for(int j=2; j<len; j++) {
rest = rest*10+n[j]-'0';
cat = rest/20;
rest = rest%20;
}
ult_cif = cat*4+ult[rest];
ult_cif %= 10;
}
ult_cif += '0';
fprintf(oFile, "%c\n" , (char)ult_cif);
}
fclose(pFile);
fclose(oFile);
return 0;
}