문제
https://www.acmicpc.net/problem/2529
해설
반복문을 돌며 숫자로된 string만 만들면 쉬운 문제
코드
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
48
49
50
51
|
#include <bits/stdc++.h>
using namespace std;
int k;
char op[10];
vector<string> ret;
bool check[10];
bool cal(char a, char b, char c)
{
if (c == '>')
return a > b;
else
return a < b;
}
void go(int idx, string tmp)
{
if (idx == k + 1)
{
ret.push_back(tmp);
return;
}
for (int i = 0; i < 10; i++)
{
if (check[i])
continue;
if (idx == 0 || cal(tmp.back(), i + '0', op[idx - 1]))
{
check[i] = true;
go(idx + 1, tmp + to_string(i));
check[i] = false;
}
}
}
int main()
{
cin >> k;
for (int i = 0; i < k; i++)
{
cin >> op[i];
}
go(0, "");
sort(ret.begin(), ret.end());
cout << ret.back() << "\n"
<< ret.front() << "\n";
}
|
cs |
'백준 알고리즘(C++)' 카테고리의 다른 글
백준 15684번 사다리 조작 ( C++ ) (0) | 2024.08.21 |
---|---|
백준 9934번 완전 이진 트리 ( C ++ ) (0) | 2024.08.21 |
백준 1987번 알파벳 ( C++ ) (0) | 2024.08.18 |
백준 3197번 백조의 호수 ( C++ ) (0) | 2024.08.18 |
백준 14497번 주난의 난 ( C++ ) (0) | 2024.08.15 |