Pagini recente » Cod sursa (job #1325186) | Cod sursa (job #2224775) | Cod sursa (job #3005343) | Cod sursa (job #1693932) | Cod sursa (job #1586863)
#include<fstream>
#include<string.h>
#define NRMAXCIFRE 101
using namespace std;
FILE*in;
ofstream out("cifra.out");
int T;
char NUMBER[NRMAXCIFRE];
int LAST[NRMAXCIFRE];
int nr_cifre_NUMBER;
int POWER(int ordin)
{
int P=ordin, solution=1;
while(P)
{
if (P % 2)
solution=(ordin*solution)%10;
ordin=(ordin*ordin)%10;
P/=2;
}
return solution;
}
void build_LAST()
{
for (int i=1; i<=100; i++)
LAST[i]=(LAST[i-1]+POWER(i))%10;
}
void read()
{
in=fopen("cifra.in", "r");
fscanf(in, "%d", &T);
build_LAST();
for (int i=1; i<=T; i++)
{
fscanf(in, "%s", &NUMBER);
nr_cifre_NUMBER=strlen(NUMBER);
if (nr_cifre_NUMBER == 1)
out<<LAST[NUMBER[0]-'0']<<'\n';
else
out<<LAST[(NUMBER[nr_cifre_NUMBER-2]-'0')*10+(NUMBER[nr_cifre_NUMBER-1]-'0')]<<'\n';
}
}
int main()
{
read();
return 0;
}