Cod sursa(job #2527947)

Utilizator memecoinMeme Coin memecoin Data 21 ianuarie 2020 10:21:36
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
#include <string.h>
#include <queue>

using namespace std;

#ifdef DEBUG
string name = "data";
#else
string name = "cifra";
#endif

ifstream fin(name + ".in");
ofstream fout(name + ".out");

int n;

int modpow(int x, int y) {
    int r = 1;
    for (int i = 1; i <= y; ++i) {
        r *= x;
        r %= 10;
    }
    return r;
}

int res[101];

int main() {
    
    int x = 0;
    
    for (int i = 1; i <= 100; ++i) {
        
        x += modpow(i, i);
        res[i] = x % 10;
    }
    
    fin >> n;
    
    for (int i = 0; i < n; ++i) {
        string s;
        fin >> s;

        int x = 0;
        
        int k = s.length();
        
        for (int j =max(0, k - 2); j <= k - 1 ; ++j) {
            x *= 10;
            x += s[j] - '0';
        }
        
        fout << res[x] << "\n";
    }
    
    return 0;
}