알고리즘/백준 알고리즘

[java] 백준 알고리즘 8958번 OX퀴즈 풀이

희랍인 조르바 2018. 5. 18. 09:56


* 풀이 소스


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
public class Baekjoon8958 {
 
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        int t = Integer.parseInt(br.readLine()); // 테스트 케이스의 개수
        
        for(int i=0; i<t; i++) {
            String oxQuiz = br.readLine(); // OX퀴즈의 결과
            int oCount = 1// O의 갯수 체크(ox퀴즈 체크에 들어갔을 때 첫번째부터 O가 있을 걸 대비해 1로 초기값)
            int score = 0// 점수
            
            for(int j=0; j<oxQuiz.length(); j++) {
                
                if(String.valueOf(oxQuiz.charAt(j)).equals("O")) { // O가 나온 결과 체크
                    score += oCount; 
                    oCount++// 연속된 O가 있으면 부여되는 점수가 올라감
                }else {
                    oCount = 1// X가 나올 경우 다음 O가 나왔을 걸 대비해 1로 초기화시킴
                }
            }
            
            bw.write(String.valueOf(score));
            bw.newLine();
        }
        bw.flush();
        
    }
 
}
 
cs