Cod sursa(job #1559599)

Utilizator daniel.sanduSandu Daniel daniel.sandu Data 31 decembrie 2015 11:27:24
Problema Cifra Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#include <string>

const int partialSum[] = {
	0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4
};

inline bool isNumber(char x) {
	return '0' <= x && x <= '9';
}

inline int cifra(int n) {
	return (partialSum[n % 20] + 4 * (((((n - (n % 20)) / 10) % 5) * 3) % 5)) % 10;
}

int main() {
	char const * const inputFile = "cifra.in",
						 * const outputFile = "cifra.out";
	std::ifstream in(inputFile);
	std::ofstream out(outputFile);
	
	std::string buffer;
	buffer.reserve(128);
	in >> buffer;
	
	while (in >> buffer) 
		if (!buffer.empty()) {
			int size = buffer.size(), n = buffer[size - 1] - '0';
			if (size > 1)
				n += 10 * (buffer[size - 2] - '0');
			out << cifra(n) << std::endl;
		}
	return 0;
}