Cod sursa(job #1442573)

Utilizator Popa.CosminPopa Andrei Popa.Cosmin Data 25 mai 2015 20:47:49
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("cifra.in");
ofstream fout("cifra.out");
int a[101];
int putere(int k){
    int sol = 1;
    for(int i = 1; i <= k; i++){
        sol *= k;
        sol %= 10;
    }
    return sol;
}

void calcul(){
    for(int i = 1; i <= 100; i++){
        a[i] = a[i - 1] + putere(i);
        a[i] %= 10;
    }
}

int main()
{
    int n,el;
    string s;
    fin >> n;
    calcul();
    for(int i = 1; i <= n; i++){
        fin >> s;
        if(s.size() > 1){
            el = (s[s.size() - 2] - '0') * 10 + s[s.size() - 1] - '0';
        } else {
            el = s[s.size() - 1] - '0';
        }
        fout << a[el] << "\n";
    }
    return 0;
}