Cod sursa(job #735759)

Utilizator NicuCJNicu B. NicuCJ Data 17 aprilie 2012 11:32:09
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <fstream>
using namespace std;
char a[1000];
int n, i, ucif, cifra;
int main()
{
	ifstream f("cifra.in");
	ofstream g("cifra.out");
	f>>n;
	for(i=1; i<=n; i++)
	{
		f>>a;
		ucif=0;
		int lim=strlen(a);
		a[-1]='0';
		a[-2]='0';
		while(lim>=0)
		{
		while(a[lim-1]>'0')
		{
			cifra=a[lim-1]-48;
			switch(cifra)
			{
			case 1:
				ucif+=1;break;
			case 2:
				{
					if(a[lim-2]%2==0)
						ucif+=4;
					else
						ucif+=6;
					break;
				}
			case 3:
				{
					if(a[lim-2]%2==0)
						ucif+=7;
					else
						ucif+=3;
					break;
				}
			case 4:
				{
					ucif+=6;
					break;
				}
			case 5:
				{
					ucif+=5;
					break;
				}
			case 6:
				{
					ucif+=6;
					break;
				}
			case 7:
				{
					if(a[lim-2]%2==0)
						ucif+=3;
					else
						ucif+=6;
					break;
				}
			case 8:
				{
					if(a[lim-2]%2==0)
						ucif+=6;
					else
						ucif+=4;
					break;
				}
			case 9:
				{
					ucif+=9;
					break;
				}
			}
			a[lim-1]--;
		}
		lim--;
		ucif%=10;
		}
		g<<ucif<<"\n";
	}
	
}