HDU 2097 sky数--进制转换

 

 

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
int change(int n,int x)
{
    int m = 0;
    while(n != 0)
    {
        m += n % x;
        n /= x;
    }
    return m;
}
int main(int argc, const char * argv[]) {
    int a;
    while(cin >> a && a)
    {
        int s ,s6 ,s8 ;
        s = change(a,10);
        s6 = change(a,16);
        s8 = change(a,12);
        if(s == s6 && s == s8)
            cout << a << " is a Sky Number." << endl;
        else
            cout << a << " is not a Sky Number." << endl;
    }
    return 0;
}

 

posted @ 2017-07-06 16:48  kimsimple  阅读(169)  评论(0编辑  收藏  举报