Cod sursa(job #1519602)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 7 noiembrie 2015 16:24:51
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <fstream>
#include <cstring>
#include <algorithm>
#include <vector>

#define infile "cifra.in"
#define outfile "cifra.out"

using namespace std;

vector<int> precalc;

char test[105];

void _precalc(void) {

	precalc.resize(100, 0);

	for (int index = 1; index < 100; ++index) {

		int temp = 1;

		for (int step = 1; step <= index; ++step) {

			temp = (temp * index) % 10;

		}

		precalc[index] = (precalc[index - 1] + temp) % 10;

	}

}

int main() {

	_precalc();

	ifstream fin(infile);
	ofstream fout(outfile);

	int testCount;

	fin >> testCount;

	while (testCount--) {

		fin >> test;

		int query = 0;

		if (strlen(test) == 1)
			query = test[0] - '0';
		else
			query = (test[strlen(test) - 2] - '0') * 10 + (test[strlen(test) - 1] - '0');

		fout << precalc[query] << '\n';

	}

	return 0;

}

//Trust me, I'm the Doctor!