ACM rightmost digit

题目描述
Given a positive integer N, you should output the most right digit of N^N.
?
输入
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).
?
输出
For each test case, you should output the rightmost digit of N^N.
?
样例输入
2
3
4
样例输出
7
6

我的代码:

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
 int t,i,a[5];
 int  n,count;
 scanf("%d",&t);
 for(i=1;i<=t;i++)
 {
  scanf("%d",&n);
  count=n;
  n=n%10;
  if(n==1)n=1;
 else if(n==0)n=0;
 else if(n==5)n=5;
 else if(n==6)n=6;
 else if(n==2){
             a[0]=6;a[1]=2;a[2]=4;a[3]=8;
             count=count%4;
             n=a[count];
              }
 else if(n==3){
            a[0]=1;a[1]=3;a[2]=9;a[3]=7;
            count=count%4;
            n=a[count];
              }
    else if(n==7){
                a[0]=1;a[1]=7;a[2]=9;a[3]=3;
             count=count%4;
             n=a[count];
              }
    else if(n==4){
               a[0]=6;a[1]=4;
            count=count%2;
            n=a[count];
               }
 else if(n==8){
               a[0]=6;a[1]=8;a[2]=4;a[3]=2;
            count=count%4;
            n=a[count];
               }
 else if(n==9){
               a[0]=1;a[1]=9;
            count=count%2;
            n=a[count];
               }
 printf("%d\n",n);
 }
   
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值