Cod sursa(job #673342)

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

int t, i, n;
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 j, l, x, s;
l=strlen(n);
if(l==1)
	{x=atoi(n[0]);
	return getval(x);
	}
else
	{x=atoi(n[l-2]);
	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;
}