Sky數
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 17086 Accepted Submission(s): 9773
#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
stack<int> s;
void hex(int x,int y)
{
int r=1;
while(x)
{
r=x%y;
s.push(r);
x=x/y;
}
}
int main()
{
int n,sum1,sum2,sum3;
while(cin>>n,n)
{
int k=n;
sum1=sum2=sum3=0;
while(k)
{
sum1+=k%10;
k=k/10;
}
hex(n,12);
while(!s.empty())
{
sum2+=s.top();
s.pop();
}
hex(n,16);
while(!s.empty())
{
sum3+=s.top();
s.pop();
}
if(sum1==sum2&&sum2==sum3)
cout<<n<<" is a Sky Number."<<endl;
else cout<<n<<" is not a Sky Number."<<endl;
}
return 0;
}