Cod sursa(job #1329257)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 29 ianuarie 2015 12:04:23
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

ifstream f("cifra.in");
ofstream g("cifra.out");

const int NMax = 105;
int a[NMax];

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;
    f >> n;
    calcul();
    for(int i = 1; i <= n; i++){
        f >> s;
        if(s.size() > 1){
            el = (s[s.size() - 2] - '0') * 10 + s[s.size() - 1] - '0';
        } else {
            el = s[s.size() - 1] - '0';
        }
        g << a[el] << "\n";
    }
    return 0;
}