Cod sursa(job #362579)

Utilizator beyond_k7aOnutu Catalin beyond_k7a Data 10 noiembrie 2009 09:07:49
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
/*
 R=2      R=3     R=0     R=1
1 - 1	 1 - 1   1 - 1	 1 - 1
2 - 4	 2 - 8   2 - 6   2 - 2
3 - 9	 3 - 7   3 - 1   3 - 3
4 - 6	 4 - 4   4 - 6   4 - 4
5 - 5	 5 - 5   5 - 5   5 - 5
6 - 6	 6 - 6   6 - 6   6 - 6
7 - 9	 7 - 3   7 - 1   7 - 7
8 - 4	 8 - 2   8 - 6   8 - 8
9 - 1	 9 - 9   9 - 1   9 - 9

s=5      s =5    s=3      s=5

*/

#include<fstream>
#include<cstring>
using namespace std;
int main()
{
	ifstream f("cifra.in");
	ofstream g("cifra.out");
	
	int t,i,j,xx,x,u,a[] = {0,1,4,7,6,5,6,3,6,9},b[] = {0,1,6,3,6,5,6,7,4,9};
	char c[102];
	f>>t;
	f.get();
	for(j=1;j<=t;j++)
	{
		u=0;
		f.getline(c,110);
		if(strlen(c)>=3)
			x=(c[strlen(c)-3]-'0')*100 + (c[strlen(c)-2]-'0')*10 + c[strlen(c)-1];
		else
		{
			if(strlen(c)==2)
				x=(c[0]-'0')*10 + c[1]-'0';
			else
				x=c[0]-'0';
		} 
		xx=x/10;
		u=((xx%10)*7)%10;
		if(xx%2==0)
			for(i=1;i<=x%10;i++)
				u+=a[i];
		else
			for(i=1;i<=x%10;i++)
				u+=b[i];
			
		u%=10;
		g<<u<<"\n";
	}
	
	
	f.close();
	g.close();
	return 0;
	
}