杭电OJ2010

#include <iostream>
using namespace std;
int main()
{
	int m, n;
	while (cin >> m >> n)
	{
		int a, b, c,x,t=0,i,s;
		for ( i = m; i <= n; i++)
		{
			x = i;
			s = i;
			a = x % 10;
			x = x / 10;
			b = x % 10;
			c = x / 10;
			if (a*a*a + b*b*b + c*c*c == i)
			{
				{
					if (t<1)
					{
						cout << i;
						t++;
					}
					else
						cout << " " << i;
				}
			}
		}
		if (t!=0 && s== n)
			cout << endl;//注意控制输出格式,当输出最后一个水仙花数的时候换行
		if (t == 0)
				cout << "no" << endl;
		}
}

猜你喜欢

转载自blog.csdn.net/weixin_42265486/article/details/83592913