作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/14 03:40:10
杭电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
杭电1097题目:下面是我的编程,求指教,为什么老师说time limited
//
#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");
}
}
//祝学习进步,更上一层楼 *^_^* !