哪里错了啊 急急急

P1157 组合的输出

```c printf("%3d%3d%3d\n",a[0],a[1],a[2]); ``` 3不能放在%和d中间。
by Hedabo_2509 @ 2022-11-30 19:56:50


@[Hedabo_2509](/user/712075) 没有问题啊,重定义
by simonG @ 2022-11-30 19:57:25


@[gaosichensb](/user/253936) ```c printf("%3d%3d%3d\n",a[0],a[1],a[2]); ``` 这里?(我是菜鸡,谢谢大佬指点
by Hedabo_2509 @ 2022-11-30 19:58:45


@[Hedabo_2509](/user/712075) 我说 ```sort``` 没问题
by simonG @ 2022-11-30 19:59:31


@[gaosichensb](/user/253936) 我知道你的意思是sort没错,但是“%3d"错了吧?
by Hedabo_2509 @ 2022-11-30 20:00:24


@[Hedabo_2509](/user/712075) 没错,很常见的写法 %3d是向右靠齐3格,%-3d是向左
by Feng_Jing @ 2022-11-30 20:18:47


sort(num)里面再sort(num),num值没有改变,不会死循环嘛
by EineKliene @ 2023-02-20 19:28:22


# [个人博客主页](https://www.ricemoon.cn/) ```cpp #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; typedef pair<int, int> PII; int n, r; int path[30]; bool st[30]; void dfs(int u, int num) { if (u == r + 1) { for (int i = 1; i <= r; i ++) cout << setw(3) << path[i]; cout << endl; } for (int i = 1; i <= n; i ++) { if (!st[i] and i > num) { st[i] = true; path[u] = i; dfs(u + 1, path[u]); st[i] = false; path[u] = 0; } } } int main() { cin >> n >> r; dfs(1, 0); return 0; } ```
by Roger_Spencer @ 2023-03-05 20:53:31


|