Pagini recente » Cod sursa (job #2201835) | Cod sursa (job #1601792) | Cod sursa (job #2752221) | Cod sursa (job #1986490) | Cod sursa (job #1695445)
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("cifra.in");
ofstream fout("cifra.out");
char S[103];
int n;
int Sol(int y)
{
int sol=0, i, x;
int lim=y%10;
for (i=1; i<=lim; i++)
{
x=(y/10)*10+i;
if (i==1)
sol+=1;
if (i==2)
{
if (x%4==2)
sol+=4;
if (x%4==0)
sol+=6;
}
if (i==3)
{
if (x%4==1)
sol+=3;
if (x%4==3)
sol+=7;
}
if (i==4)
sol+=6;
if (i==5)
sol+=5;
if (i==6)
sol+=6;
if (i==7)
{
if (x%4==1)
sol+=7;
if (x%4==3)
sol+=3;
}
if (i==8)
{
if (x%4==2)
sol+=4;
if (x%4==0)
sol+=6;
}
if (i==9)
{
sol+=9;
}
}
return sol;
}
int main()
{
int i, a, b, x;
fin>>n;
fin.get();
for (i=1; i<=n; i++)
{
fin.getline(S, 105);
a=0; b=0;
if (strlen(S)>=2)
a=S[strlen(S)-2]-'0';
b=S[strlen(S)-1]-'0';
x=a*10+b;
fout<<(7*a+Sol(x))%10<<'\n';
}
return 0;
}