Cod sursa(job #1327669)

Utilizator b10nd3Oana Mancu b10nd3 Data 26 ianuarie 2015 22:49:05
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<stdlib.h>
#include<stdio.h>
#include<fstream>
#include<math.h>


/*
s=pow(1,1)+pow(2,2)+...+pow(9,9);

abcde => s*d+s*c*10+s*b*100+s*a*1000+x;

x=pow(1,1)+...+pow(e,e)

%10
*/

using namespace std;

int main(){
ifstream in; ofstream out;
in.open("cifra.in"); out.open("cifra.out");
out.clear();

int t,no, v[10],s=0;
string x;

v[0]=0;
for(int i=1;i<=9;i++){
    v[i]=(v[i-1]+(int)pow(i,i)%10)%10; 
    s=s+v[i];
}

in>>t;
for(int i=1;i<=t;i++){
	no=0;
	in>>x; 
	if(x.length()>=2)
	  no=x[x.length()-2]-'0'*s;
	no=no+v[x[x.length()-1]-'0'];	  
    out<<no%10<<endl;
}


	
return 0;	
}