Guest User

Untitled

a guest
Jan 22nd, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. class Node{
  2.    
  3.     char info;
  4.     Node prev, next;
  5.    
  6.     public Node(char info, Node prev, Node next){
  7.         this.info = info;
  8.         this.prev = prev;
  9.         this.next = next;
  10.     }
  11.    
  12. }
  13.  
  14. void solve() throws IOException{
  15.     char[] c = in.readLine().toCharArray();
  16.     int i = 0;
  17.     while (c[i] == '<' || c[i] == '>') i++;
  18.     if (i == c.length) return;
  19.     Node first = new Node(c[i], null, null);
  20.     first.prev = first;
  21.     first.next = first;
  22.     Node cur = first;
  23.     for (; i < c.length; i++){
  24.         if (c[i] == '<') cur = cur.prev;
  25.         else if (c[i] == '>') cur = cur.next;
  26.         else{
  27.             Node node = new Node(c[i], cur, cur.next);
  28.             if (cur.next == cur) node.next = node;
  29.             cur = cur.next = node;
  30.         }
  31.     }
  32.     cur = first;
  33.     do{
  34.         out.print(cur.info);
  35.         cur = cur.next;
  36.     } while (cur != cur.next);
  37. }
Add Comment
Please, Sign In to add comment