Pagini recente » Cod sursa (job #2291909) | Cod sursa (job #1911725) | Cod sursa (job #1609436) | Cod sursa (job #1285457) | Cod sursa (job #2214498)
#include <iostream>
#include<fstream>
#include<cstring>
using namespace std;
ifstream fin("cifra.in"); /*input and output files*/
ofstream fout("cifra.out");
int s[105],T,n;
char N[105]; /*there we'll get the numbers by a char array*/
int Pow(int b,int e) /*User Defined Function for lifting at power*/
{
int r = 1;
while(e > 1)
{
if(e % 2 == 1) r = r * b;
b = b * b; e /= 2;
}
return r * b;
}
int main() /* Main Function */
{
for(int i = 1;i <= 99; i++) /* There we've generated an array for getting */
s [i] = (s[i-1] + Pow(i % 10,(i % 100 - 1) % 4 + 1)) % 10; /* we can't only make 10 values because the base is different at first 100 numbers*/
fin >> T; /*we read how many numbers are in input file*/
while(T--) /*same as for (i = t,i <= n; i--)*/
{
fout >> N; /*There I've read the number*/
if (N[1] == 0) n = N[0] - '0'; /*if number value is 0 then we add 0 value to n*/
else n = (N[strlen(N) - 2] - '0') * 10 + N[strlen(N) - 1] - '0'; /*else we got the last to and mak a number
*/
out1<< s[n%100] << endl; /*There we printed the solution*/
}
}