Cod sursa(job #2443261)

Utilizator Asgari_ArminArmin Asgari Asgari_Armin Data 27 iulie 2019 11:26:53
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>

using namespace std;

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

int ucfact[] = { 1, 4, 7, 6, 5, 6, 3, 6, 9 }; //ultima cifra la uc(1^1) = 1, uc(2^2) = 4, ... ,uc(9^9) = 9
int sp[] = { 1, 5, 2, 8, 3, 9, 2, 8, 7 };

int main() {
    string numar;
    int t, i;
    fin >> t;
    for( i = 0; i < t; ++i ){
      fin >> numar;
      if( numar.size() == 1 )
        fout << sp[numar[0] - '0' - 1] << "\n";
      else
        fout << (sp[numar[numar.size() - 1] - '0' - 1] + (ucfact[numar[numar.size() - 2] - '0' - 1] * 7) % 10) << "\n";
    }
    return 0;
}