forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF.cpp
More file actions
41 lines (35 loc) · 717 Bytes
/
F.cpp
File metadata and controls
41 lines (35 loc) · 717 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
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
freopen("prefixes.in", "r", stdin);
freopen("prefixes.out", "w", stdout);
cin >> s;
if (s.length()==1) {
cout << s << endl;
} else {
vector<char> head;
vector<char> tail;
char m, M;
int l = s.length();
m = min(s[0], s[1]);
M = max(s[0], s[1]);
head.push_back(m);
tail.push_back(M);
for(int i=2; i<l; i++) {
if(m>=s[i]) {
head.push_back(s[i]);
m = s[i];
} else {
tail.push_back(s[i]);
}
}
for(int i=head.size()-1; i>=0; i--) {
printf("%c", head[i]);
}
for(int i=0; i<tail.size(); i++) {
printf("%c", tail[i]);
}
cout << endl;
}
}