Cod sursa(job #2923344)

Utilizator alexmorosanuMorosanu Alexandru alexmorosanu Data 12 septembrie 2022 21:00:48
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>
#include <cstring>

using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
const int last_digits[] = {0,1,5,2,8,3,9,2,8,7,7,8,4,7,3,8,4,1,5,4};
int T,i,m;
char n[111];
int main()
{
    f >> T;
    for(i = 1;i <= T;i++)
    {
        f >> n;
        if(strlen(n) == 1)
            m = n[0] - '0';
        else
            m = (n[0] - '0') * 10 + (n[1] - '0');
        if(m / 10 % 2 == 0)
            g << (m / 10 * 7 + last_digits[m % 10]) % 10 << '\n';
        else
            g << (m / 10 * 7 - 7 + last_digits[m % 20]) % 10 << '\n';
    }
    return 0;
}