1032 -- 水仙花数

来源:互联网 发布:软件资源网站 编辑:程序博客网 时间:2024/06/05 19:00

水仙花数

Time Limit:1000MS  Memory Limit:65536K
Total Submit:831 Accepted:336

Description

请判断一个数是不是水仙花数。
其中水仙花数定义各个位数立方和等于它本身的三位数。

Input

有多组测试数据,每组测试数据以包含一个整数n(100<=n<1000)
输入0表示程序输入结束。

Output

如果n是水仙花数就输出Yes
否则输出No

Sample Input

1531540

Sample Output

YesNo

Source

C语言基础

    using System;    using System.Collections.Generic;    using System.Linq;    using System.Text;    namespace AK1032 {        class Program {            static bool jtahstu(int n) {                int x = n % 10, y = n / 10 % 10, z = n / 100;                if (x * x * x + y * y * y + z * z * z == n) return true;                return false;            }            static void Main(string[] args) {                string sb;                while ((sb = Console.ReadLine()) != null) {                    int n = int.Parse(sb);                    if (n == 0) break;                    if (jtahstu(n))                        Console.WriteLine("Yes");                    else                        Console.WriteLine("No");                }            }        }    }


0 0
原创粉丝点击