Cod sursa(job #1599284)

Utilizator mateinMatei Nistor Ionut matein Data 13 februarie 2016 19:05:05
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main() {
	int t,len,rest,cat,ult_cif,aux;
	char n[100];
	int ult[20] = {1, 5, 2, 8, 3, 9, 2, 0, 9, 9, 0, 6, 9, 5, 0, 6, 3, 7, 6, 6}; 
	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, 100, pFile);
		len = strlen(n)-1;		
		if( len == 1) {
			aux = n[0]-'0';
			ult_cif = ult[aux-1];
		} 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];
				cat = rest/20;
				rest = rest%20;
			}
			ult_cif = cat*6+ult[rest-1];
			ult_cif %= 10;
		}
		ult_cif += '0';
		fprintf(oFile, "%c\n" , (char)ult_cif);
	}
	fclose(pFile);
	fclose(oFile);
	return 0;
}