Cod sursa(job #1435066)

Utilizator BFlorin93Balint Florin-Lorand BFlorin93 Data 11 mai 2015 23:31:15
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
// Cifra.cpp : Defines the entry point for the console application.
//
#include <stdlib.h>
#include <stdio.h>
#include "string"
#include "fstream"
#include <iostream>

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');		
		}
		else 
		{
			last = str[str.length() - 1] - '0';
		}
		if (last > 0)
			outFile << (7 * beforeLast + table[last - 1]) % 10 << "\n";
		else
			outFile << (7 * beforeLast) % 10 << "\n";
	}

	inFile.close();
	outFile.close();
	return 0;
}