杭电ACM2097--Sky数

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

 

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

 

#include 
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;
}


 

转载于:https://www.cnblogs.com/acmwangpeng/p/5524889.html

你可能感兴趣的:(杭电ACM2097--Sky数)