Cod sursa(job #599597)

Utilizator valentin.harsanValentin Harsan valentin.harsan Data 29 iunie 2011 10:54:42
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;

ifstream in("cifra.in");
ofstream out("cifra.out");

int t,u[101];

int main() {
	
	int i,j,a,s;
	char x[102];
	
	for(i=1;i<100;++i) {
		a=1;
		
		for(j=1;j<=i;++j)
			a=(a*i)%10;
		
		u[i]=(u[i-1]+a)%10;
	}
	
	in >> t;
	
	while(t--) {
		in >> x;
		s=strlen(x);
		
		if(s==1)
			out << u[x[0]-'0'] << "\n";
		else
			out << u[(x[s-2]-'0')*10 + x[s-1]-'0'] << "\n";
	}
	
	return 0;
}