杭电OJ2010 C++

来源:互联网 发布:网络节目视听许可证 编辑:程序博客网 时间:2024/06/05 08:51
#include <iostream>
#include <cmath>
using namespace std;


bool judge(int num)
{
int a,b,c;
int num1;
num1=num;
a=num1/100;
num1=num1%100;
b=num1/10;
num1=num1%10;
c=num1/1;
if(num==(a*a*a+b*b*b+c*c*c))
{
return true;
}
else
return false;
}
int main()
{
int m,n;
while(cin>>m>>n)
{
int count=0;//count用于标记以便空格的输入
int i=m; //i=m用于标记是否有水仙花数
for(int j=m;j<=n;j++)
{
if(judge(j))
{
if(!count)
{
cout<<j;
count++;
}
else
cout<<" "<<j;
i++;
}
}
if(i==m)
{
cout<<"no";
}
cout<<endl;

}
return 0;
0 0
原创粉丝点击