Pagini recente » Cod sursa (job #3129805) | Cod sursa (job #921661) | Cod sursa (job #2749851) | Cod sursa (job #2531859) | Cod sursa (job #1435063)
// Cifra.cpp : Defines the entry point for the console application.
//
#include <stdlib.h>
#include <stdio.h>
#include "string"
#include "fstream"
int table[10] = { 1, 5, 2, 8, 3, 9, 2, 8, 7, 7};
using namespace std;
int main()
{
ifstream inFile("cifra.in");
ofstream outFile("cifra.out");
int T;
string str;
inFile >> T;
for (int i = 0; i < T; i++)
{
int beforeLast = 0, last = 0;
inFile >> str;
if (str.length() > 1){
last = (str[str.length() - 1] - '0');
beforeLast = (str[str.length() - 2] - '0') * 10;
}
else
{
last = str[str.length() - 1] - '0';
}
outFile << (9 * beforeLast + table[last - 1]) % 10 << "\n";
}
inFile.close();
outFile.close();
return 0;
}