Cod sursa(job #1453075)

Utilizator lflorin29Florin Laiu lflorin29 Data 22 iunie 2015 18:13:34
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cstring>
using namespace std;
char s[105];
int last[102];
int log (int a, int b){
    int sol = 1;
    for (;b;b>>=1){
            if (b & 1) {
                    sol=sol*(a)%10;
            b--;}
            a=(a*a)%10;}
            return sol;
}
void generare()
{int i,j;
    for( i=1;i<=101;i++)
    {
        last[i]=(last[i-1]+log(i,i))%10;
}
}

int main(){
    ifstream cin ("cifra.in");
    ofstream cout ("cifra.out");
    int t, n,x;
    cin>>t;
    generare();
    while (t--){
            cin>>s+1;
    n = strlen(s+1);
        if (n > 1) {
                x = last[s[n]-'0'+(s[n-1]-'0')*10];
   cout<<x<<"\n";}
  else {
     cout<<last[s[n]-'0']<<"\n";
    }
    }
    return 0;
}