Cod sursa(job #2429309)

Utilizator IulianOleniucIulian Oleniuc IulianOleniuc Data 9 iunie 2019 00:17:53
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <string>
#include <fstream>

using std::string;
std::ifstream fin("cifra.in");
std::ofstream fout("cifra.out");

int main() {
//  const int pre[] = {0, 1, 4, 7, 6, 5, 6, 3, 6, 9, 0, 1, 6, 3, 6, 5, 6, 7, 4, 9, 0};
    const int sum[] = {0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4, 4};

    int t; fin >> t;
    while (t--) {
        string str; fin >> str;
        int n = str[str.size() - 1] - '0';
        if (str.size() > 1) n += (str[str.size() - 2] - '0') * 10;
        if (str.size() > 2) n += (str[str.size() - 3] - '0') * 100;

        int c = n / 20 % 10, r = n % 20;
        fout << (sum[20] * c + sum[r]) % 10 << '\n';
    }

    fout.close();
    return 0;
}