码迷,mamicode.com
首页 > 其他好文 > 详细

HDU Sky数 2079 简单易懂的代码

时间:2014-11-10 13:42:18      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   os   sp   div   log   

题目

http://acm.hdu.edu.cn/showproblem.php?pid=2097

思路

既然要求和 十进制数字各个位数上的和是相同的, 那么16,12进制转换完之后也是10进制表示的

 

#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <stack>
using namespace std;
#define maxn 15000int Sky(int n,int k)
{
    int num = 0;
    while(n)
    {
        num += n%k;
        n /= k;
    }
    return num;
}
int main()
{
    int n;
    while(cin >> n, n)
    {
        int a = Sky(n,10);
        int b = Sky(n,12);
        int c = Sky(n,16);
        if(a == b && b == c)
            printf("%d is a Sky Number.\n",n);
        else
            printf("%d is not a Sky Number.\n",n);
    }
    return 0;
}

 

HDU Sky数 2079 简单易懂的代码

标签:style   blog   http   io   color   os   sp   div   log   

原文地址:http://www.cnblogs.com/chenchengxun/p/4086911.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!