閱讀83 返回首頁    go 阿裏雲 go 技術社區[雲棲]


水仙花數

Problem F

水仙花數

時間限製:1000 ms  |  內存限製:65535 KB
描述
請判斷一個數是不是水仙花數。
其中水仙花數定義各個位數立方和等於它本身的三位數。
輸入
有多組測試數據,每組測試數據以包含一個整數n(100<=n<1000)
輸入0表示程序輸入結束。
輸出
如果n是水仙花數就輸出Yes
否則輸出No
樣例輸入
153
154
0
樣例輸出
Yes
No
#include <cstdio>
#include <iostream>
using namespace std;

int main()
{
    int n;

    while (cin >> n && n != 0)
    {
        int gw = n % 10;
        int sw = n / 10 % 10;
        int bw = n / 100;

        if (n == gw * gw * gw + sw * sw * sw + bw * bw * bw)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


最後更新:2017-04-02 15:14:59

  上一篇:go 1077: Slash
  下一篇:go 5個數求最值