hdu 2097 Sky数

题解:

  比较简单,求各个位数之和。

代码如下:

#include <stdio.h>

int main()
{
    int n, tmp, sum1, sum2, sum3;
    while (scanf("%d", &n) && n)
    {
        sum1 = sum2 = sum3 = 0;
        tmp = n;
        while (tmp)
        {//十进制各个数位和
            sum1 += tmp % 10;
            tmp /= 10;
        }
        tmp = n;
        while (tmp)
        {//十六进制各个数位和
            sum2 += tmp % 16;
            tmp /= 16;
        }
        if (sum1 != sum2)
            printf("%d is not a Sky Number.\n", n);
        else
        {
            tmp = n;
            while (tmp)
            {
                sum3 += tmp % 12;
                tmp /= 12;
            }
            if (sum1 != sum3)
                printf("%d is not a Sky Number.\n", n);
            else
                printf("%d is a Sky Number.\n", n);
        }
    }
    return 0;
}

 

posted on 2013-01-25 15:36  zm001  阅读(782)  评论(0编辑  收藏  举报