You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
601 B

#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int a[N];
bool st[N];
int n = 9;
void dfs(int step) {
if (step == n + 1) {
if ((a[1] * 100 + a[2] * 10 + a[3]) + (a[4] * 100 + a[5] * 10 + a[6]) == a[7] * 100 + a[8] * 10 + a[9]) {
for (int i = 1; i <= 9; i++) printf("%d ", a[i]);
printf("\n");
}
return;
}
for (int i = 1; i <= n; i++) {
if (!st[i]) {
a[step] = i;
st[i] = true;
dfs(step + 1);
st[i] = false;
}
}
}
int main() {
dfs(1);
return 0;
}