-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva11988.java
More file actions
46 lines (45 loc) · 1.51 KB
/
Copy pathUva11988.java
File metadata and controls
46 lines (45 loc) · 1.51 KB
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
import java.util.*;
import java.io.*;
public class Uva11988
{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr = new PrintWriter(System.out);
StringBuilder sb = new StringBuilder();
while( br.ready() ){
LinkedList<Character> linkedList = new LinkedList<>();
LinkedList<Character> tmp = new LinkedList<>();
char [] a = br.readLine().toCharArray();
boolean insertAtFirst = false;
for (int i = 0; i < a.length; i++) {
if(a[i] == '[') {
if(insertAtFirst){
linkedList.addAll(0,tmp);
tmp.clear();
}
else insertAtFirst = true;
}
else if(a[i] == ']') {
insertAtFirst = false;
linkedList.addAll(0,tmp);
tmp.clear();
}
else
if (insertAtFirst)
tmp.addLast(a[i]);
else {
linkedList.addLast(a[i]);
}
}
linkedList.addAll(0,tmp);
tmp.clear();
Iterator<Character> it = linkedList.iterator() ;
while(it.hasNext())
sb.append(it.next());
sb.append("\n");
}
pr.print(sb.toString());
pr.close();
br.close();
}
}