-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1251.cpp
More file actions
47 lines (42 loc) · 963 Bytes
/
1251.cpp
File metadata and controls
47 lines (42 loc) · 963 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
// 1251. 단어 나누기
// 2021.06.09
// 브루트 포스
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string s;
cin >> s;
string ans = "";
string a = "";
string b = "";
string c = "";
for (int i = 1; i < s.size() - 1; i++)
{
for (int j = 1; j < s.size() - i; j++)
{
// 세 단어로 나누기
a = s.substr(0, i);
b = s.substr(i, j);
c = s.substr(i + j, s.size() - i - j);
// 각각 뒤집기
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
reverse(c.begin(), c.end());
// 합치기
string tmp = a + b + c;
if (ans == "")
{
ans = tmp;
}
else if (ans > tmp)
{
ans = tmp;
}
}
}
cout << ans << endl;
return 0;
}