Pagini recente » Cod sursa (job #2387124) | Cod sursa (job #1508757) | Cod sursa (job #2663085) | Cod sursa (job #1360981) | Cod sursa (job #2443261)
#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;
}