Pagini recente » Cod sursa (job #2048225) | Cod sursa (job #2359456) | Cod sursa (job #830426) | Cod sursa (job #2119428) | Cod sursa (job #1925936)
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream f("cifra.in"); ofstream g("cifra.out");
int i,n,cif,a[105]; string b;
int cifra(int x)
{
int c,y;
y=x;
x=x%10;
if(x==0) c=0;
if(x==1) c=1;
if(x==2)
{
if (y%4==0) c=6;
if (y%4==1) c=2;
if (y%4==2) c=4;
if (y%4==3) c=8;
}
if(x==3)
{
if (y%4==0) c=1;
if (y%4==1) c=3;
if (y%4==2) c=9;
if (y%4==3) c=7;
}
if(x==4)
{
if (y%2==0) c=6;
if (y%2==1) c=4;
}
if(x==5) c=5;
if(x==6) c=6;
if(x==7)
{
if (y%4==0) c=1;
if (y%4==1) c=7;
if (y%4==2) c=9;
if (y%4==3) c=3;
}
if(x==8)
{
if (y%4==0) c=6;
if (y%4==1) c=8;
if (y%4==2) c=4;
if (y%4==3) c=2;
}
if(x==9)
{
if (y%2==0) c=1;
if (y%2==1) c=9;
}
return c;
}
int main()
{
f>>n;
a[0]=0;
cif=0;
for(i=1;i<=100;i++)
{
a[i]=(a[i-1]+cifra(i))%10;
}
for(i=1;i<=n;i++)
{
int nr;
f>>b;
nr=b.length();
nr--;
if (nr==0)
{
g<<a[b[nr]-'0']<<'\n';
}
else
{
g<<a[(b[nr-1]-'0')*10+b[nr]-'0']<<'\n';
}
}
return 0;
}