Source code for submission s672

FQ.java

  1.  
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5.  
  6. /*
  7.  * To change this template, choose Tools | Templates
  8.  * and open the template in the editor.
  9.  */
  10.  
  11. /**
  12.  *
  13.  * @author cteam94
  14.  */
  15. public class FQ {
  16. int n;
  17. String line;
  18.  
  19. public static void main(String[] args) throws IOException {
  20.  
  21. while((new FQ()).readLine(br));
  22. }
  23.  
  24. public boolean readLine(BufferedReader br) throws IOException {
  25. line = br.readLine();
  26. if (line == null) return false;
  27.  
  28. n = line.length();
  29.  
  30. int x = p(0, 0);
  31. System.out.println(x % 1000000);
  32.  
  33. return true;
  34. }
  35.  
  36. public int p(int o, int c){
  37. if (o<c || o>n/2) return 0;
  38. if (o+c==n) return 1;
  39. if (line.charAt(o+c)=='(') return p(o+1,c);
  40. if (line.charAt(o+c)==')') return p(o,c+1);
  41. if (line.charAt(o+c)=='.') return p(o+1,c) + p(o,c+1);
  42. return 0;
  43. }
  44. }
  45.