Mai intai trebuie sa te autentifici.

Cod sursa(job #74948)

Utilizator ada_sAda-Mihaela Solcan ada_s Data 29 iulie 2007 20:45:30
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.45 kb
#include <fstream>
#include <string.h>

std::ifstream f1("cifra.in");
std::ofstream f2("cifra.out");

int sol[100]={0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4, 4, 5, 9, 6, 2, 7, 3, 6, 2, 1, 1, 2, 8, 1, 7, 2, 8, 5, 9, 8, 8, 9, 3, 0, 6, 1, 7, 0, 6, 5, 5, 6, 2, 5, 1, 6, 2, 9, 3, 2, 2, 3, 7, 4, 0, 5, 1, 4, 0, 9, 9, 0, 6, 9, 5, 0, 6, 3, 7, 6, 6, 7, 1, 8, 4, 9, 5, 8, 4, 3, 3, 4, 0, 3, 9, 4, 0, 7, 1, 0};

int main()
{
  int k, i, n, l;
	char x, y, t[110];
	f1>>k;
	for (i=0; i<k; i++)
	{
	  f1>>t;
		l=strlen(t);
		if (l==1)
		{
			x='0';
			y=t[l-1];
		}//if
		else
		{
			x=t[l-2];
			y=t[l-1];
		}//else
		switch (x)
		{
			case '0' : n=0;
								 break;
			case '1' : n=10;
								 break;
			case '2' : n=20;
								 break;
			case '3' : n=30;
								 break;
			case '4' : n=40;
                 break;
			case '5' : n=50;
                 break;
			case '6' : n=60;
                 break;
			case '7' : n=70;
                 break;
			case '8' : n=80;
								 break;
 			case '9' : n=90;
								 break;
		}//switch
		switch (y)
		{
			case '0' : n+=0;
								 break;
			case '1' : n+=1;
								 break;
			case '2' : n+=2;
								 break;
			case '3' : n+=3;
								 break;
			case '4' : n+=4;
								 break;
			case '5' : n+=5;
								 break;
			case '6' : n+=6;
								 break;
			case '7' : n+=7;
								 break;
			case '8' : n+=8;
								 break;
 			case '9' : n+=9;
								 break;
		}//switch
		f2<<sol[n]<<"\n";
	}//for i
	return 0;
}//main