-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17413.java
More file actions
41 lines (39 loc) · 1.18 KB
/
17413.java
File metadata and controls
41 lines (39 loc) · 1.18 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
Stack<Character> stack = new Stack<>();
int i=0;
String result="";
while(i<s.length()){
char c = s.charAt(i);
if(c=='<'){
while(s.charAt(i)!='>'){
result+=s.charAt(i++);
}
result+=s.charAt(i++);
}
else if(('0'<=c&&c<='9')||('a'<=c&&c<='z')) {
while (s.charAt(i)!=' '&&s.charAt(i)!='<') {
stack.push(s.charAt(i++));
if (i == s.length())
break;
}
int j = stack.size();
while (j != 0) {
result += stack.pop();
j--;
}
}
else{
result+=c;
i++;
}
}
System.out.println(result);
}
}