Cod sursa(job #308194)

Utilizator GulosSerban Petrescu Gulos Data 26 aprilie 2009 12:49:46
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include<iostream>
#include<fstream>
#include<string>

using namespace std;

int main(){
	ifstream fin("cifra.in");
	ofstream fout("cifra.out");
	int t,i,x,y,s;
	int s1[11]={0,1,5,2,8,3,9,2,8,7};
	int s2[11]={0,1,7,0,6,1,7,4,8,7};
	char nr[103];
	nr[0]='0';
	fin>>t;
	for (i=0;i<t;i++){
		fin.get();
		fin.get(nr+1,101,'\n');
		x=nr[strlen(nr)-1]-'0';
		y=nr[strlen(nr)-2]-'0';
		if (y%2==0)
			s=s1[x];
		else
			s=s2[x];
		s+=(y%2)*7;
		y=y/2;
		s+=(y%5)*4;
		s%=10;
		fout<<s<<"\n";
	}
	fout.close();
	return 0;
}