杭电ACM2097--Sky数

时间:2022-08-20 18:51:12

这题思路很简单,把10,12,16进制数都按位相加,然后进行比较即可。

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

<span style="font-size:18px;">#include <stdio.h>
int peng(int m)
{
int a;
a = m/1000+(m%1000)/100+(m%100)/10+m%10;
return a;
}
int peng16(int m)
{
int a;
a = m/4096+m%4096/256+m%256/16+m%16;
return a;
}
int peng12(int m)
{
int a;
a = m/1728+m%1728/144+m%144/12+m%12;
return a;
}
int main()
{
int m;
while (scanf("%d",&m)!=EOF&&m!=0)
{
//printf("%d %d %d\n",peng(m),peng12(m),peng16(m));
if (peng(m)==peng12(m)&&peng(m)==peng16(m))
printf("%d is a Sky Number.\n",m);
else
printf("%d is not a Sky Number.\n",m);
}
return 0;
}</span>