A hard puzzle

时间:2014-11-10 13:23:11   收藏:0   阅读:253
Problem Description
lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.
this puzzle describes that: gave a and b,how to know the a^b‘s the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.
 
Input
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
 
Output
For each test case, you should output the a^b‘s last digit number.
 
Sample Input
7 66
8 800
 
Sample Output
9
6
 
  1 #include <stdio.h>
  2 
  3 int main(){
  4     int a;
  5     int b;
  6     int number;
  7     char two[5]="2486";
  8     char three[5]="3971";
  9     char four[3]="46";
 10     char seven[5]="7931";
 11     char eight[5]="8426";
 12     char nine[3]="91";
 13 
 14     while(scanf("%d%d",&a,&b)!=EOF){
 15         number=a%10;
 16 
 17         if(number==0){
 18             printf("0\n");
 19             continue;
 20         }
 21 
 22         if(number==1){
 23             printf("1\n");
 24             continue;
 25         }
 26 
 27         if(number==2){
 28             b%=4;
 29 
 30             if(b==0)
 31                 b=4;
 32 
 33             printf("%c\n",two[b-1]);
 34             continue;
 35         }
 36 
 37         if(number==3){
 38             b%=4;
 39 
 40             if(b==0)
 41                 b=4;
 42 
 43             printf("%c\n",three[b-1]);
 44             continue;
 45         }
 46 
 47         if(number==4){
 48             b%=2;
 49 
 50             if(b==0)
 51                 b=2;
 52 
 53             printf("%c\n",four[b-1]);
 54             continue;
 55         }
 56 
 57         if(number==5){
 58             printf("5\n");
 59             continue;
 60         }
 61 
 62         if(number==6){
 63             printf("6\n");
 64             continue;
 65         }
 66 
 67         if(number==7){
 68             b%=4;
 69 
 70             if(b==0)
 71                 b=4;
 72 
 73             printf("%c\n",seven[b-1]);
 74             continue;
 75         }
 76 
 77         if(number==8){
 78             b%=4;
 79 
 80             if(b==0)
 81                 b=4;
 82 
 83             printf("%c\n",eight[b-1]);
 84             continue;
 85         }
 86 
 87         if(number==9){
 88             b%=2;
 89 
 90             if(b==0)
 91                 b=2;
 92 
 93             printf("%c\n",nine[b-1]);
 94             continue;
 95 
 96         }
 97 
 98     }
 99     
100     return 0;
101 }

 

 

原文:http://www.cnblogs.com/zqxLonely/p/4086933.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!