Pagini recente » Cod sursa (job #363360) | Cod sursa (job #1935887) | Cod sursa (job #1993678) | Cod sursa (job #507091) | Cod sursa (job #759648)
Cod sursa(job #759648)
#include <fstream>
#include <string>
using namespace std;
string nr;
int t, n, dim;
const int rest[] = {0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4};
int main()
{
int i;
ifstream f("cifra.in");
ofstream g("cifra.out");
f >> t;
for(i = 1; i <= t; ++i) {
f >> nr;
dim = nr.size();
if(dim == 1)
n = nr[dim - 1] - '0';
else if(dim == 2)
n = nr[dim - 1] - '0' + (nr[dim - 2] - '0') * 10;
else
n = nr[dim - 1] - '0' + (nr[dim - 2] - '0') * 10 + (nr[dim - 3] - '0') * 100;
g << ((4 * ((n / 20) % 10) % 10) + rest[n % 20]) % 10 << "\n";
}
return 0;
}