Pagini recente » Cod sursa (job #1600941) | Cod sursa (job #2197083) | Cod sursa (job #3040860) | Cod sursa (job #1217207) | Cod sursa (job #3136472)
#include <fstream>
#include <cstdlib>
#include <cstring>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int T;
int solve(int x)
{
if (x == 0 || x == 9)
return 7;
if (x == 1)
return 1;
if (x == 2)
return 5;
if (x == 3 || x == 7)
return 2;
if (x == 4 || x == 8)
return 8;
if (x == 5)
return 3;
return 9; ///x == 6
}
int charToInt(const char* x)
{
int len = strlen(x);
if (len == 1)
return atoi(x);
return atoi(x + (len - 2));
}
void citire()
{
f >> T;
while (T--)
{
char x[110];
f >> x;
int val = charToInt(x);
if (val < 10)
g << solve(val) << '\n';
else
g << ((val / 10) * 7 + solve(val % 10)) % 10 << '\n';
}
}
int main()
{
citire();
return 0;
}