您的位置:首页 > 其它

1114 -- 水仙花数

2015-08-30 10:23 225 查看
水仙花数
Time Limit:1000MS Memory Limit:65536K

Total Submit:627 Accepted:201
Description
输出区间[a,b】中的所有水仙花数,若三位数ABC满足ABC=A^3+B^3+C^3,则称为水仙花数。例如153=1^3+5^3+3^3,所以 153是水仙花数

Input
一个区间【a,b】,b>a>0

Output
输出区间[a,b】中的所有水仙花数(每一个1行)

Sample Input
100 154

Sample Output
Hint
153

Source
lrj程序入门

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AK1114 {
class Program {
static void Main(string[] args) {
int a, b, x, y, z, i;
string[] values = Console.ReadLine().Split(' ');
a = int.Parse(values[0]); b = int.Parse(values[1]);
if (a < 100) a = 100;
if (b > 999) b = 999;
for (i = a; i <= b; i++) {
x = i / 100;
y = i / 10 % 10;
z = i % 10;
if (x * x * x + y * y * y + z * z * z == i)
Console.WriteLine(i);
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: