Cod sursa(job #2214502)

Utilizator Alex03Runcan Alexandru Alex03 Data 19 iunie 2018 11:30:44
Problema Cifra Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#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--)*/
    {
        fin >> 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
        */
        fout<< s[n%100] << endl; /*There we printed the solution*/
    }
}