Cod sursa(job #1133334)
Utilizator | Data | 4 martie 2014 19:17:16 | |
---|---|---|---|
Problema | Cifra | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.96 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fcin("cifra.in");
ofstream fcout("cifra.out");
int t,n,j,x,i,s;
fcin>>t;
for (i=1;i<=t;i++)
{
fcin>>n;s=0;
for (j=1;j<=n;j++)
{
if (j%10==0)
x=0;
else if(j%10==1)
x=1;
else if (j%10==5)
x=5;
else if(j%10==6)
x=6;
else if (j%10==4)
{
if (j%2!=0)
x=4;
else x=6;
}
else if (j%10==2)
{
if((j%100)%4==0)
x=6;
if((j%100)%4==1)
x=2;
if((j%100)%4==2)
x=4;
else x=8;
}
else if (j%10==3)
{
if((j%100)%4==0)
x=1;
if((j%100)%4==1)
x=3;
if((j%100)%4==2)
x=9;
else x=7;
}
else if (j%10==7)
{
if((j%100)%4==0)
x=1;
if((j%100)%4==1)
x=7;
if((j%100)%4==2)
x=9;
else x=3;
}
else if (j%10==8)
{
if((j%100)%4==0)
x=6;
if((j%100)%4==1)
x=8;
if((j%100)%4==2)
x=4;
else x=2;
}
else if(j%10==9)
{
if (j%2!=0)
x=9;
else x=1;
}
s=s+x;
if (s>9)
s=s%10;
}
fcout<<s<<endl;
}
fcin.close();
fcout.close();
return 0;
}