杭电1097题目:下面是我的编程,求指教,为什么老师说time limited

杭电1097题目:下面是我的编程,求指教,为什么老师说time limited
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
讨厌讨厌讨厌ll 1年前 已收到1个回答 举报

lcdrotna 幼苗

共回答了14个问题采纳率:92.9% 举报

//
#include
int main()
{
int i, n, a, b;
while(scanf("%d%d", &a, &b) != EOF)
{
n = a % 10;
switch(n)
{
case 0:
case 1:
case 5:
case 6:
printf("%d", n); //尾数为0,1,5,6 时, a^b以后还是一样的
break;
case 2: //尾数为2
if(b % 4 == 0)printf("6");
else if(b % 4 == 1)printf("2");
else if(b % 4 == 2)printf("4");
else printf("8");
break;
case 3: //尾数为3
if(b % 4 == 0)printf("1");
else if(b % 4 == 1)printf("3");
else if(b % 4 == 2)printf("9");
else printf("7");
break;
case 4:
if(b % 2)printf("4");
else printf("6");
break;
case 7:
if(b % 4 == 0)printf("1");
else if(b % 4 == 1)printf("7");
else if(b % 4 == 2)printf("9");
else printf("3");
break;
case 8:
if(b % 4 == 0)printf("6");
else if(b % 4 == 1)printf("8");
else if(b % 4 == 2)printf("4");
else printf("2");
break;
case 9:
if(b % 2)printf("9");
else printf("1");
break;
}
printf("n");
}
}
//祝学习进步,更上一层楼 *^_^* !

1年前

9
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.934 s. - webmaster@yulucn.com