Cod sursa(job #683194)

Utilizator andreipasalauPasalau Andrei andreipasalau Data 20 februarie 2012 09:59:01
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.34 kb
#include<fstream.h>
ifstream f("cifra.in");
ofstream g("cifra.out");
int ultima(int numar)
{
	return numar%10;
}
main()
{
	long T,i,k,j,u,rez;
	f>>T;
	for(i = 0; i < T; i++)
	{
		rez = 1;
		f>>k;
		for(j = 2; j <= k; j++)
		{
			u = ultima(j);
			if(u == 1)
				rez += 1;
			else if(u == 5)
				rez += 5;
			else if(u == 6)
				rez += 6;
			else if(u == 2)
			{
				if(j % 4 == 1)
					rez += 2;
				else if(j % 4 == 2)
					rez += 4;
				else if(j % 4 == 3)
					rez += 8;
				else if(j % 4 == 0)
					rez += 6;
			}
			else if (u == 3)
			{
				if(j % 4 == 1)
					rez += 3;
				else if(j % 4 == 2)
					rez += 9;
				else if(j % 4 == 3)
					rez += 7;
				else if(j % 4 == 0)
					rez += 1;
			}
			else if (u == 4)
			{
				if(j % 2 == 1)
					rez += 4;
				else
					rez += 6;
			}
			else if (u == 7)
			{
				if(j % 4 == 1)
					rez += 7;
				else if(j % 4 == 2)
					rez += 9;
				else if(j % 4 == 3)
					rez += 3;
				else if(j % 4 == 0)
					rez += 1;
			}
			else if (u == 8)
			{
				if(j % 4 == 1)
					rez += 8;
				else if(j % 4 == 2)
					rez += 4;
				else if(j % 4 == 3)
					rez += 2;
				else if(j % 4 == 0)
					rez += 6;
			}
			else if (u == 9)
			{
				if(j % 2 == 1)
					rez += 9;
				else
					rez += 1;
			}	
		}
		rez = ultima(rez);
		g<<rez<<"\n";
	}
}