-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2992.cpp
More file actions
59 lines (53 loc) · 674 Bytes
/
2992.cpp
File metadata and controls
59 lines (53 loc) · 674 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
48
49
50
51
52
53
54
55
56
57
58
59
// 2992. 크면서 작은 수
// 2020.01.04
// 브루트 포스, 반복문
#include<iostream>
#include<vector>
using namespace std;
int vSize;
vector<int> v;
int visit[6];
int ans = 1000000;
int n;
void go(int cnt, int num)
{
if (cnt == vSize)
{
if (num > n && num < ans)
{
ans = num;
}
return;
}
num *= 10;
for (int i = 0; i < vSize; i++)
{
if (!visit[i])
{
visit[i] = 1;
go(cnt + 1, num + v[i]);
visit[i] = 0;
}
}
}
int main()
{
cin >> n;
int k = n;
while (k > 0)
{
v.push_back(k % 10);
k /= 10;
}
vSize = v.size();
go(0, 0);
if (ans == 1000000)
{
cout << 0 << endl;
}
else
{
cout << ans << endl;
}
return 0;
}