杭电HDU练习题_hdu_1.2.4

作者在 2013-04-29 16:13:18 发布以下内容
/*输入的第一行是一个整数,测试的数目。
 *在每一行输入一个数字m,计算m^m 的最后一位
*/

#include <stdio.h>

int main(void)
{
    int line, number, last, tmp;

    scanf("%d", &line);

    while(line--)
    {
        last = 1;
        scanf("%d", &number);

        tmp = number % 10;

        switch(tmp)
        {
            case 2:
                if(number % 4 == 0) printf("6\n");
                if(number % 4 == 1) printf("2\n");
                if(number % 4 == 2) printf("4\n");
                if(number % 4 == 3) printf("8\n");
                break;
            case 3:
                if(number % 4 == 0) printf("1\n");
                if(number % 4 == 1) printf("3\n");
                if(number % 4 == 2) printf("9\n");
                if(number % 4 == 3) printf("7\n");
                break;
            case 4:
                if(number % 2 == 0) printf("6\n");
                if(number % 2 == 1) printf("4\n");
                break;
            case 7:
                if(number % 4 == 0) printf("1\n");
                if(number % 4 == 1) printf("7\n");
                if(number % 4 == 2) printf("9\n");
                if(number % 4 == 3) printf("3\n");
                break;
            case 8:
                if(number % 4 == 0) printf("6\n");
                if(number % 4 == 1) printf("8\n");
                if(number % 4 == 2) printf("4\n");
                if(number % 4 == 3) printf("2\n");
                break;
            case 9:
                if(number % 2 == 0) printf("1\n");
                if(number % 2 == 1) printf("9\n");
                break;
            default:
                printf("%d\n", tmp);break;

        }
        //printf("%d\n", last);
    }

    return 0;
}
HDU | 阅读 879 次
文章评论,共0条
游客请输入验证码
浏览41748次