Platinum Group II fifth title

Title: Spring is the season of flowers, daffodils is one of the most charming representatives, there is a narcissistic number Mathematically, he is defined as:
"the number of Narcissus" refers to a three-digit number, the digits of its cube and equal to its own, for example: 153 = 1 3 + 5 3 + 3 ^ 3.
Now all numbers daffodils required output within the range of m and n.
Input
input multiple sets of data, each representing one line, comprising two integers m and n (100 <= m <= n <= 999).
Output
For each test case, all numbers daffodils required output within a given range, that is, the number of output must be greater than or equal daffodils m, and less than equal to n, if there are a plurality, in ascending order is required in the output line, separated by a space between;
If the number does not exist in daffodils given range, outputting no;
output row for each test case.
Solution: establishing m, n, and the number of array 3, the input to establish circulation m, n, is satisfied (100 <= m <= n <= 999) under the premise of establishing whether the number of cycles is determined between a number satisfying mn daffodils , followed by the format of the output to

#include <iostream>
using namespace std;
int main()
{
	int m, n, a[3];
	while (cin >> m >> n)
	{
		int c = 0, d = 0;
		if (m >= 100 && n >= m && n <= 999)
		{
			for (int i = m; i <= n; i++)
			{
				int k = i;
				for (int j = 0; j < 3; j++)
				{
					a[j] = k % 10;
					k = (k - a[j]) / 10;
				}
				if (i ==a[0]*a[0]*a[0] + a[1] * a[1] * a[1] + a[2] * a[2] * a[2])
				{
					c++;
					if (d == 1)
					{
						cout << " ";
					}
					cout << i;
					d = 1;
				}
			}
			if (c == 0) cout << "no";
			cout << endl;
		}
	}
}

Guess you like

Origin blog.csdn.net/weixin_43981315/article/details/84978472