Cod sursa(job #1696687)

Utilizator GilgodRobert B Gilgod Data 29 aprilie 2016 17:16:40
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <iostream>
#include <fstream>
#include <string>

const char IN[] = "cifra.in";
const char OUT[] = "cifra.out";

#define MAXL 101

int A[MAXL];

int T;
int N;

using namespace std;

int dcd(int b, int e)
{
	if (e == 0)
		return 0;
	if (e == 1)
		return 1;
	switch (b) {
	case 0: return 0;
	case 1: return 1;
	case 2: return 
		(e % 4 == 1) ? 2 :
		(e % 4 == 2) ? 4 :
		(e % 4 == 3) ? 8 : 6;
	case 3: return
		(e % 4 == 1) ? 3 :
		(e % 4 == 2) ? 9 :
		(e % 4 == 3) ? 7 : 1;
	case 4: return (e % 2 == 1) ? 4 : 6;
	case 5: return 5;
	case 6: return 6;
	case 7: return
		(e % 4 == 1) ? 7 :
		(e % 4 == 2) ? 9 :
		(e % 4 == 3) ? 3 : 1;
	case 8: return dcd(2, e + 3);
	case 9: return (e % 2 == 1) ? 9 : 1;
	}
}

inline void preprocess()
{
	for (int i = 1; i < MAXL; ++i)
		A[i] = (A[i - 1] + dcd(i, i)) % 10;
}

inline void read_data()
{
	ifstream fin(IN);
	ofstream fout(OUT);
	fin >> T;
	string s;
	while (T--) {
		fin >> s;
		int num = s[s.length() - 1] - '0';
		if (s.length() > 1)
			num += 10 * (s[s.length() - 2] - '0');
		fout << A[num] << endl;
	}
	fout.close();
	fin.close();
}

int main()
{
	preprocess();
	for (int i = 0; i < MAXL; ++i)
		cout << A[i] << ' ';
	cout << endl;
	read_data();
	return 0;
}