Cod sursa(job #673356)

Utilizator TIBSTiberiu Iorgulescu 321CA TIBS Data 4 februarie 2012 12:38:04
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include<fstream>
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;

int t, i;
char n[101];
ifstream f("cifra.in");
ofstream g("cifra.out");

int getval(int x)
{if(x==1)
	return 1;
if(x==2)
	return 4;
if(x==3)
	return 7;
if(x==4)
	return 6;
if(x==5)
	return 5;
if(x==6)
	return 6;
if(x==7)
	return 3;
if(x==8)
	return 6;
if(x==9)
	return 9;
if(x==0)
	return 0;
}

int getval2(int x)
{if(x==1)
	return 1;
if(x==2)
	return 6;
if(x==3)
	return 3;
if(x==4)
	return 6;
if(x==5)
	return 5;
if(x==6)
	return 6;
if(x==7)
	return 7;
if(x==8)
	return 4;
if(x==9)
	return 9;
if(x==0)
	return 0;
}

int parse()
{int l, x, s;
char aux[2];
l=strlen(n);
if(l==1)
	{aux[1]=n[0];
	aux[2]=0;
	x=atoi(aux);
	return getval(x);
	}
else
	{aux[0]=n[l-2];
	x=atoi(aux);
	s=(7*x)%10;
	if(x%2==0)
		s+= getval(x);
	else
		s+= getval2(x);
	return s%10;
	}
}
int main()
{f>>t;
for(i=1;i<=t;i++)
	{f>>n;
	g<<parse()<<endl;
	}
f.close();
g.close();
return 0;
}