-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy path8.2.cpp
More file actions
47 lines (41 loc) · 928 Bytes
/
8.2.cpp
File metadata and controls
47 lines (41 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* 题目名称:全排列
* 题目来源:北京大学复试上机题
* 题目链接:http://t.cn/Ai0K0hXZ
* 代码作者:杨泽邦(炉灰)
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
const int MAXN = 10;
bool visit[MAXN];
char sequence[MAXN];
void GetPermutation(string str, int index) {
if (index == str.size()) {
for (int i = 0; i < str.size(); ++i) {
printf("%c", sequence[i]);
}
printf("\n");
}
for (int i = 0; i < str.size(); ++i) {
if (visit[i]) {
continue;
}
visit[i] = true;
sequence[index] = str[i];
GetPermutation(str, index + 1);
visit[i] = false;
}
return ;
}
int main() {
string str;
while (cin >> str) {
sort(str.begin(), str.end());
GetPermutation(str, 0);
printf("\n");
}
return 0;
}