思路:其实只需求各个位数之和,不需要进行进制转换,开始想的复杂了,同时采用函数进行书写,可大大提高效率和减少代码量
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int f(int n, int m)
{
int sum = 0;
while (n)
{
sum += n % m;
n = n / m;
}
return sum;
}
int main ()
{
//freopen("E:\input.txt", "r", stdin);
int n;
while ((cin >> n) && n)
{
if ((f(n, 10) == f(n, 16)) && (f(n, 12) == f(n, 16)))
{
cout << n << " is a Sky Number." << endl;
}
else
{
cout << n << " is not a Sky Number." << endl;
}
}
return 0;
}