Pagini recente » Cod sursa (job #2347898) | Cod sursa (job #1409110) | Cod sursa (job #2816802) | Cod sursa (job #1400016) | Cod sursa (job #1066529)
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
ifstream f("cifra.in",ios::in);
ofstream g("cifra.out",ios::out);
int pow(int a, int b)
{
if(b==0)
return 1;
if(b==1)
return a;
else
return a*pow(a,b-1);}
int main()
{
char a[100],k;
int n,i,s,T,suma[100],j;
while(!f.eof())
{f>>T;
for(i=1;i<=T;i++)
{
f>>a;
n=strlen(a);
k=a[n-1];
s=k-48;
suma[i]=0;
for(j=1;j<=s;j++)
suma[i]=(suma[i]+pow(j,j)%10)%10;}
for(i=1;i<=T;i++)
g<<suma[i]<<endl;}
f.close();
g.close();
return 0;}