-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP11988.cpp
51 lines (45 loc) · 878 Bytes
/
P11988.cpp
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 <iostream>
#include <stdio.h>
#include <stack>
#include <string>
#include <sstream>
typedef std::string String;
typedef std::stack<String> Stack;
typedef std::stringstream SS;
bool isNormalLetter(char c) {
return c != '[' && c != ']' && isprint(c);
}
int main() {
String input;
char c;
while(std::cin >> input) {
Stack s;
SS ss;
unsigned int j = 0;
while(j < input.size() && isprint(c = input[j++])) {
if(c == '[') {
unsigned int k = j;
while(isNormalLetter(c = input[k]))
++k;
if(k == j)
continue;
input[k] = '\0';
s.push(String(&input[j]));
input[k] = c;
j = k;
}
else if(c == ']') {
// nop
}
else {
ss << c;
}
}
// First print Stack, then SS.
while(!s.empty()) {
std::cout << s.top();
s.pop();
}
std::cout << ss.str() << std::endl;
}
}