39-水仙の数

816 ワード

タイトルの説明:
一つの数が水仙の数かどうかを判断してください.ここで、水仙の数は、各ビット数立方体とそれ自体の3ビット数を定義します.
説明を入力:
       ,             n(100<=n<1000)
  0        。

出力の説明:
  n        Yes
    No

サンプル入力:
153
154
0

サンプル出力:
Yes
No

ACコード:
#include 
using namespace std;
int main(){
  int n,m;
  ios::sync_with_stdio(false);
  while(cin >> n){
    int m = n;
    if(n==0) break;
    int a = n%10;
    int b = n/10%10;
    int c = n/100;
    //cout << a << b << c;
    int temp = a*a*a + b*b*b + c*c*c;
    if(temp == m){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  return 0;
}