Cod sursa(job #2252099)

Utilizator vescaDamian-Teodor BELES vesca Data 2 octombrie 2018 12:13:20
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#include <string>

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

const int lastDigitNN[10] = {0, 1, 4, 7, 6, 5, 6, 3, 6, 9};

int main() {
    int T;
    fin >> T;
    while (T--) {
        std::string x;
        fin >> x;

        int sizeOfx = x.size(), number, lastDigit = 0;

        if (sizeOfx > 1) {
            number = std::stoi(x.substr(sizeOfx - 2));
        }
        else {
            number = std::stoi(x);
        }

        for (int i = 0; i <= number; ++i) {
            lastDigit += lastDigitNN[i % 10];
            lastDigit %= 10;
        }

        fout << lastDigit << "\n";
    }
    return 0;
}