Cod sursa(job #1739210)

Utilizator wilson182Alexandrina Panfil wilson182 Data 8 august 2016 21:27:04
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include<bits/stdc++.h>
using namespace std;
ifstream fin("cifra.in");
ofstream fout("cifra.out");
int n;
string s;
char c[105];
int uc[105];
int cifra(int x)
{
	unsigned long long s = 1;
	for (int j = 1; j <= x; j++) s = (s*x)%10;
	return s%10;
}
int main()
{
	uc[0]=0;
	fin >> n;
	for (int i = 1; i <= 100; i++) uc[i] = (uc[i - 1] + cifra(i)) % 10;
	c[0] = '0';
	int a;
	for (int j = 1; j <= n; j++) {
		fin >> s;
        int l = s.size();
        if(l == 1) a=s[0]-'0';
        else if(l >= 2) a=(s[l - 2] - '0')*10 + (s[l - 1] - '0');
        fout << uc[a] << '\n';
	}
	return 0;
}