Files
Story-With-Thanh/JKT015 - GÕ BÀN PHÍM.java
2022-12-15 23:51:04 +07:00

26 lines
805 B
Java

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
Stack<Character> a = new Stack<>();
Stack<Character> b = new Stack<>();
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == '<') {
if (!a.empty())
b.push(a.pop());
} else if (s.charAt(i) == '>') {
if (!b.empty())
a.push(b.pop());
} else if (s.charAt(i) == '-') {
if (!a.empty())
a.pop();
} else
a.push(s.charAt(i));
}
while (!a.empty())
b.push(a.pop());
while(!b.empty()) System.out.print(b.pop());
}
}