Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 24th, 2012  |  syntax: Java  |  size: 1.04 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  public class Sample1 {
  2.         public static void main (String[] args){
  3.             Scanner con = new Scanner(System.in);
  4.             //String s=con.nextLine();
  5.             String s=con.nextLine();
  6.             char []ss=s.toCharArray();
  7.            
  8.            
  9.             //int end = s.length();
  10.             int t=0;
  11.            
  12.  
  13.             //for(int i=0;i<end; i++){
  14.             for(int i=0;i<s.length();i++){    
  15.                
  16.                
  17.                 if(ss[i] =='('){
  18.                     t++;
  19.                    
  20.                    
  21.                 }else {
  22.                     t--;
  23.                    
  24.                    
  25.                 }
  26.                
  27.                 if((t<0)){
  28.                   break;
  29.                 }
  30.             }
  31.  
  32.             if(t<0){
  33.                 System.out.print("IMPOSSIBLE");
  34.             } else{
  35.                
  36.                 for(int i=0;i<t;i++){
  37.                     s+=')';
  38.                 }
  39.                 System.out.print(s);
  40.             }
  41.  
  42.         }
  43.     }