【题目描述】求100∼999100∼999 中的水仙花数。若三位数ABCABC ,ABC=A3+B3+C3ABC=A3+B3+C3 ,则称ABCABC 为水仙花数。 例如153153 ,13+53+33=1+125+27=15313+53+33=1+125+27=153 ,则153153 是水仙花数。 【输入】无 【输出】由小到大输出满足条件的数,每个数占一行。 假设需要输出两个数:119,100。需要输出以下形式: 100 119 【输入样例】无 【输出样例】无 |
【代码】
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
int main()
{
int n;
int g,s,b;
for(n=100;n<=999;n++)
{
g=n%10;
s=n/10%10;
b=n/100;
if((pow(g,3)+pow(s,3)+pow(b,3))==n)
{
cout<<n<<endl;
}
}
return 0;
}
【做题链接】
信息学奥赛一本通(C++版)在线评测系统http://ybt.ssoier.cn:8088/problem_show.php?pid=2029