Cod sursa(job #2231279)

Utilizator caesar2001Stoica Alexandru caesar2001 Data 13 august 2018 17:22:08
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <bits/stdc++.h>
#define lsb(x) x & -x

using namespace std;
ifstream in("cifra.in");
ofstream out("cifra.out");

int sol[] = {0, 1, 4, 7, 6, 5, 6, 3, 6, 9, 0, 1, 6, 3, 6, 5, 6, 7, 4, 9};
string s;

int main() {
    int t;
    in >> t;
    while(t --) {
        in >> s;
        int nr = s[s.size() -1] - '0';
        if(s.size() > 1)
            nr += (10 * (s[s.size() - 2] - '0'));
        int ans = 0;
        for(int i = 1; i <= nr; i ++) {
            int j = i % 20;
            ans += sol[j];
        }
        ans %= 10;
        out << ans << "\n";
    }

    return 0;
}