Tuesday, September 15, 2015

Computing height as stacking bowl using parenthesis, JungOl Question 2604, (http://www.jungol.co.kr/problem.php?id=2604)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.*;
public class Main {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        
        String str = sc.nextLine();
        
        char[] strArray = str.toCharArray();
        
        int height = 0;
        
        for(int i = 0; i < strArray.length;i++){
         
         if(i == 0){
          height += 10;
         }else if(strArray[i] == '('){
          
          if(strArray[i-1] == '('){
           height += 5;
          }else{
           height += 10;
          }
          
         }else if(strArray[i] == ')'){
          if(strArray[i-1] == ')'){
           height += 5;
          }else{
           height += 10;
          }
         }
        }
        
        System.out.println(height);
 }
 
}

No comments:

Post a Comment