40分求解答!!样例跑过了,不知道怎么改
查看原帖
40分求解答!!样例跑过了,不知道怎么改
1262722
smurf_h楼主2024/3/8 11:21
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;


int num[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int a, b, c;

int cal(int l, int r)
{
	int res = 0;
	for (int i = l; i <= r; i++)
	{
		res = res * 10 + num[i];
	}
	return res;
}

int main()
{
	std::cin >> a >> b >> c;
	int cnt = 0;

	while (std::next_permutation(num, num + 9))
	{
		for (int i = 0; i < 9; i++)
		{
			for (int j = i + 1; j < 9; j++)
			{
				int x = cal(0, i);
				int y = cal(i + 1, j);
				int z = cal(j + 1, 8);

				if (b * c * x == a * c * y && a * c * y == a * b * z)
				{
					std::cout << x << ' ' << y << ' ' << z << std:: endl;
					cnt++;
				}
			}
		}
	}

	if (cnt == 0) std::cout << "N0!!!";

	return 0;
}
2024/3/8 11:21
加载中...