Tranvick

blabla

Sep 22nd, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class Main {
  5.     public static void main(String []args) {
  6.         Scanner in = new Scanner(System.in);
  7.         String s = in.nextLine();
  8.         in.close();
  9.         StringBuilder sb = new StringBuilder(s);
  10.        
  11.         int n = 0, fl = 0, beg = 0, en = 0;
  12.         int i = 0;
  13.         while (i<sb.length()) {
  14.             if (sb.charAt(i) == '(') {
  15.                 n++;
  16.                 beg = i;
  17.                 fl = 0;
  18.             }
  19.             if (sb.charAt(i) == ')') {
  20.                 n--;
  21.                 if (fl == 0) {
  22.                     sb.delete(beg, i + 1);
  23.                     fl = 1;
  24.                     i = beg;
  25.                 }
  26.             }
  27.             i++;
  28.         }
  29.         System.out.println(sb);
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment