Cod sursa(job #1599330)

Utilizator mateinMatei Nistor Ionut matein Data 13 februarie 2016 19:30:06
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 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, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4, 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, 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*4+ult[rest-1];
			ult_cif %= 10;
		}
		ult_cif += '0';
		fprintf(oFile, "%c\n" , (char)ult_cif);
	}
	fclose(pFile);
	fclose(oFile);
/*	int s=0,p,test =41;
	
	for(int i=1;i<=test;i++) {
		p=1;
		for(int j=1;j<=i;j++) {
			aux = i%10;
			p *= aux;
			p = p%10;
		}
		s = s+p;
	}*/
		
	return 0;
}