题解 | 水仙花数

水仙花数

https://www.nowcoder.com/practice/dc943274e8254a9eb074298fb2084703

using System;
public class Program {
    public static void Main() {
         string s;
         bool t = true;
        while ((s = Console.ReadLine()) != null){
            string[] str = s.Split();
            int m = int.Parse(str[0]);
            int n = int.Parse(str[1]);
            for (int i = m; i <= n; i++){
                int a = (int) Math.Pow(i % 10, 3);
                int b = (int) Math.Pow((i / 10) % 10, 3);
                int c = (int) Math.Pow(i / 100, 3);
                if (i == a + b + c){
                    Console.Write("{0} ",i);
                    t = false;
                }   
            }
            if (t){
                Console.WriteLine("no");
            }
        }

    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
04-30 18:05
空屿编号:你把墨镜摘下来是不是这样😭
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务