题解 | 水仙花数
水仙花数
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");
}
}
}
}

查看16道真题和解析