半夜求教C语言。
小弟在做一个ACM的题目,要求得出数字N的N次方以后的最右边数值,我写了下面这个程序,在C里面运行没有问题,但是传到网站上就显示答案错误了,估计是程序里面有不对的地方,希望各位大大指正,谢谢了。题目要求:
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Output
For each test case, you should output the rightmost digit of N^N.
Sample Input
2
3
4
Sample Output
7
6
程序如下
[i]#include <stdio.h>
void main ()
{
int a,s,t,i,b[100],j;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&a);
s=a%10;
switch(s)
{
case 0:b[i]=0;
break;
case 1:b[i]=1;
break;
case 2: j=a%4;
switch(j)
{
case 0:b[i]=6;
break;
case 1:b[i]=2;
break;
case 2:b[i]=4;
break;
case 3:b[i]=8;
break;
}
break;
case 3:j=a%4;
switch(j)
{
case 0:b[i]=1;
break;
case 1:b[i]=3;
break;
case 2:b[i]=9;
break;
case 3:b[i]=7;
break;
}
break;
case 4:j=a%2;
switch(j)
{
case 0:b[i]=6;
break;
case 1:b[i]=4;
break;
}
break;
case 5:b[i]=5;
break;
case 6:b[i]=6;
break;
case 7:j=a%4;
switch(j)
{
case 0:b[i]=1;
break;
case 1:b[i]=7;
break;
case 2:b[i]=9;
break;
case 3:b[i]=3;
break;
}
break;
case 8:
j=a%4;
switch(j)
{
case 0:b[i]=6;
break;
case 1:b[i]=8;
break;
case 2:b[i]=4;
break;
case 3:b[i]=2;
break;
}
break;
case 9:
j=a%2;
switch(j)
{
case 0:b[i]=1;
break;
case 1:b[i]=9;
break;
}
}
}
for(i=0;i<t;i++)printf("%d\n",b);
}