Cod sursa(job #1435063)

Utilizator BFlorin93Balint Florin-Lorand BFlorin93 Data 11 mai 2015 23:16:55
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
// 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;
}