1,2,3…9 这九个数字组成一个分数,其值恰好为1/3,如何组法?
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int x[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
do{
int a = x[0] * 1000 + x[1] * 100 + x[2] * 10 + x[3];
int b = x[4] * 10000 + x[5] * 1000 + x[6] * 100 + x[7] * 10 + x[8];
if (a * 3 == b) cout << a <<' ' << b<<' ';
} while (next_permutation(x, x + 9));
return 0;
}
参考全排列资料 next_permutation
点击打开链接