-
Notifications
You must be signed in to change notification settings - Fork 0
/
prob17413.java
65 lines (61 loc) · 1.36 KB
/
prob17413.java
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
60
61
62
63
64
65
package sw_typeIM;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;
//백준 17413 단어 뒤집기 2
public class prob17413 {
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String tmp = bf.readLine();
char[] input = tmp.toCharArray();
char[] output = new char[input.length];
Stack<Character> temp = new Stack<>();
boolean flag = false;
int index = 0;
for (int i = 0; i < input.length; i++) {
if(!flag) {
if(input[i]=='<') {
if(!temp.isEmpty()) {
while(!temp.isEmpty()) {
output[index++] = temp.pop();
}
}
flag = true;
output[index++] = input[i];
continue;
}
else if(input[i]==' ') {
if(!temp.isEmpty()) {
while(!temp.isEmpty()) {
output[index++] = temp.pop();
}
}
output[index++] = input[i];
continue;
}
else { //스택에 넣는 과정
temp.add(input[i]);
}
}
else {
if(input[i]=='>') {
flag = false;
output[index++] = input[i];
continue;
}
else {
output[index++] = input[i];
continue;
}
}
}
if(!temp.isEmpty()) {
while(!temp.isEmpty()) {
output[index++] = temp.pop();
}
}
for (int i = 0; i < output.length; i++) {
System.out.print(output[i]);
}
}
}