Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node{
- char info;
- Node prev, next;
- public Node(char info, Node prev, Node next){
- this.info = info;
- this.prev = prev;
- this.next = next;
- }
- }
- void solve() throws IOException{
- char[] c = in.readLine().toCharArray();
- int i = 0;
- while (c[i] == '<' || c[i] == '>') i++;
- if (i == c.length) return;
- Node first = new Node(c[i], null, null);
- first.prev = first;
- first.next = first;
- Node cur = first;
- for (; i < c.length; i++){
- if (c[i] == '<') cur = cur.prev;
- else if (c[i] == '>') cur = cur.next;
- else{
- Node node = new Node(c[i], cur, cur.next);
- if (cur.next == cur) node.next = node;
- cur = cur.next = node;
- }
- }
- cur = first;
- do{
- out.print(cur.info);
- cur = cur.next;
- } while (cur != cur.next);
- }
Add Comment
Please, Sign In to add comment