Cod sursa(job #1230712)

Utilizator Luncasu_VictorVictor Luncasu Luncasu_Victor Data 19 septembrie 2014 00:53:11
Problema Cifra Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <fstream>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");

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

int Modulo(string S) {
	int X = 0;
	for (int i = 0; i < S.length(); i++) {
		X = (X * 10 + S[i] - '0') % 100;
	}
	return X;
}

int Solution(int X) {
	int S = 0;
	for (int i = 1; i <= X; i++) {
		S = (S + P[i % 10][(i-1) % 4]) % 10;
	}
	return S;
}

int T, N;
string S;

int main(){
	
 	f >> T;
 	
 	while (T--) {
 		f >> S;	
 		g << Solution(Modulo(S)) << "\n";
 	}
  		
	return 0;
}