Cod sursa(job #2554532)

Utilizator Wister1043Silaghi Razvan-Andrei Wister1043 Data 23 februarie 2020 01:15:10
Problema Cifra Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

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

int main()
{
    int par[10]={0, 1, 5, 12, 18, 23, 29, 32, 38, 47};
    int impar[10]={0, 1, 7, 10, 16, 21, 27, 34, 38, 47};
    int T,a,c,s;
    char n[102];
    fin>>T;
    for(int j=1;j<=T;j++)
    {
        fin>>n;
        a=strlen(n);
        c=0;
        if (a-2>=0)
        {
            c=n[a-2]-'0';
        }
        if(c%2==0)
        {
            s=(c*7)%10+par[n[a-1]-'0'];
        }
        else
        {
            s=(c*7)%10+impar[n[a-1]-'0'];
        }
        fout<<s%10<<endl;
    }
    return 0;
}