Pagini recente » Infoarena Monthly 2014 - Runda 9, Solutii | Cod sursa (job #912547) | Cod sursa (job #2354324) | Cod sursa (job #1356384) | Cod sursa (job #17528)
Cod sursa(job #17528)
using namespace std;
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
FILE*f=fopen("cifra.in", "r");
FILE*g=fopen("cifra.out", "w");
char v1[102], a, b;
long n;
int i, nr, N, epr, v[101], I, I1;
fscanf(f, "%ld", &n);
epr=0;
for (i=1;i<100;i++){
I=i%10;
I1=i%4;
if (I1==0) I1=4;
I=pow(I, I1);
epr=(epr+I)%10;
v[i]=epr;
}
for (i=1;i<=n;i++){
fscanf(f,"%s",&v1);
nr=strlen(v1);
N=0;
if (nr!=1){
a=v1[nr-2];
if (a=='0') N=0;
else if (a=='1') N=1;
else if (a=='2') N=2;
else if (a=='3') N=3;
else if (a=='4') N=4;
else if (a=='5') N=5;
else if (a=='6') N=6;
else if (a=='7') N=7;
else if (a=='8') N=8;
else if (a=='9') N=9;
}
b=v1[nr-1];
if (b=='0') N=N*10;
else if (b=='1') N=N*10+1;
else if (b=='2') N=N*10+2;
else if (b=='3') N=N*10+3;
else if (b=='4') N=N*10+4;
else if (b=='5') N=N*10+5;
else if (b=='6') N=N*10+6;
else if (b=='7') N=N*10+7;
else if (b=='8') N=N*10+8;
else if (b=='9') N=N*10+9;
fprintf(g,"%d\n",v[N]);
}
fclose(f);
fclose(g);
return 0;
}