8000 Update 6603_1.cpp · jm-Back/basic-algo-lecture@2051f72 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2051f72

Browse files
Update 6603_1.cpp
1 parent e33a4c8 commit 2051f72

File tree

1 file changed

+17
-39
lines changed

1 file changed

+17
-39
lines changed

0x0C/solutions/6603_1.cpp

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,31 @@
1-
// Authored by : yongjunleeme
1+
// Authored by : qwee158
22
// Co-authored by : -
3-
// http://boj.kr/54ced2c7e27e40da93c95a150d93d56e
3+
// http://boj.kr/091a628889c24cd79d04dd2abe6e8b5d
44
#include <bits/stdc++.h>
55
using namespace std;
66

7-
int n;
8-
int arr[15];
9-
int num[15];
10-
bool isused[15];
7+
int k, input[20], arr[10];
118

12-
void func(int k){
13-
if(k == 6){
14-
bool flag = true;
15-
int tmp = -1;
16-
for(int i = 0; i < 6; i++){
17-
if(tmp > num[arr[i]]) flag = false;
18-
tmp = num[arr[i]];
19-
}
20-
21-
if(flag){
22-
for(int i = 0; i < 6; i++)
23-
cout << num[arr[i]] << " ";
24-
cout << "\n";
25-
}
9+
void func(int cnt, int cur) {
10+
if (cnt == 6) {
11+
for (int i = 0; i < 6; i++) cout << arr[i] << ' ';
12+
cout << '\n';
2613
return;
2714
}
28-
for(int i = 0; i < n; i++){
29-
if(!isused[i]){
30-
arr[k] = i;
31-
isused[i] = 1;
32-
func(k+1);
33-
isused[i] = 0;
34-
}
15+
for (int i = cur; i < k; i++) {
16+
arr[cnt] = input[i];
17+
func(cnt + 1, i + 1);
3518
}
3619
}
3720

38-
int main(void){
21+
int main(void) {
3922
ios::sync_with_stdio(0);
4023
cin.tie(0);
41-
42-
while(1){
43-
cin >> n;
44-
if(n == 0) break;
45-
for(int i = 0; i < n; i++)
46-
cin >> num[i];
47-
sort(num, num+n);
48-
func(0);
49-
cout << "\n";
50-
fill(num, num+n, 0);
51-
fill(arr, arr+n, 0);
24+
while (1) {
25+
cin >> k;
26+
if (k == 0) break;
27+
for (int i = 0; i < k; i++) cin >> input[i];
28+
func(0, 0);
29+
cout << '\n';
5230
}
5331
}

0 commit comments

Comments
 (0)
0