Cod sursa(job #311209)

Utilizator popoiu.georgeGeorge Popoiu popoiu.george Data 2 mai 2009 22:26:57
Problema Cifra Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.65 kb
#include<fstream>
#include<stdio.h>
#include<math.h>
using namespace std;

fstream /*f("cifra.in",ios::in),*/g("cifra.out",ios::out);

long long t,v[40000];

long long ultima(long long a)
{
long long c,c1,f;
c=a%10;
if(c==0){f=0;goto end;}
else if(c==1){f=1;goto end;}
else if(c==2)
	{
	c1=a%4;
	if(c1==0){f=6;goto end;}
	else if(c1==1){f=2;goto end;}
	else if(c1==2){f=4;goto end;}
	else if(c1==3){f=8;goto end;}
	}
else if(c==3)
	{
	c1=a%4;
	if(c1==0){f=1;goto end;}
	else if(c1==1){f=3;goto end;}
	else if(c1==2){f=9;goto end;}
	else if(c1==3){f=7;goto end;}
	}
else if(c==4)
	{
	c1=a%2;
	if(c1==0){f=6;goto end;}
	else if(c1==1){f= 4;goto end;}
	}
else if(c==5){f=5;goto end;}
else if(c==6){f=6;goto end;}
else if(c==7)
	{
	c1=a%4;
	if(c1==0){f= 1;goto end;}
	else if(c1==1){f=7;goto end;}
	else if(c1==2){f=9;goto end;}
	else if(c1==3){f=3;goto end;}
	}
else if(c==8)
	{
	c1=a%4;
	if(c1==0){f=6;goto end;}
	else if(c1==1){f=8;goto end;}
	else if(c1==2){f=4;goto end;}
	else if(c1==3){f=2;goto end;}
	}
else if(c==9)
	{
	c1=a%2;
	if(c1==0){f=1;goto end;}
	else if(c1==1){f= 9;goto end;}
	}
end : return f;
}

long long suma(long long a)
{
long long i,final=0;
for(i=1;i<=a;i++){final+=ultima(i);final%=10;}
//final%=10;
return final;
}

/*long long nr_cifre(long long a)
{
long long nr=0;
while(a)
	{
	a/=10;
	nr++;
	}
return pow(10,nr);
}*/

int main()
{
//char aux[100];
long i;
FILE * f;
f=fopen("cifra.in","r");
fscanf(f,"%lld",&t);
for(i=1;i<=t;i++)
	{
	fscanf(f,"%lld",&v[i]);
	}
for(i=1;i<=t;i++)
	{
	if(v[i]<100)g<<suma(v[i])<<endl;
	else g<<suma(v[i]%100)<<endl;
	}
return 0;
}