본문 바로가기
Baekjoon Online Judge

[BOJ] 백준 8958번: OX퀴즈 (Java)

by 프로그래 밍구 2023. 3. 11.

문제링크

https://www.acmicpc.net/problem/8958

 

8958번: OX퀴즈

"OOXXOXXOOO"와 같은 OX퀴즈의 결과가 있다. O는 문제를 맞은 것이고, X는 문제를 틀린 것이다. 문제를 맞은 경우 그 문제의 점수는 그 문제까지 연속된 O의 개수가 된다. 예를 들어, 10번 문제의 점수

www.acmicpc.net


나의코드

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
                                               
        int testCase = Integer.parseInt(br.readLine());
        
        String arr[] = new String[testCase];
                                               
        for(int i = 0; i < testCase; i++){
            arr[i] = br.readLine();
        }
        
        for(int i = 0; i < testCase; i++){
            int count = 0;
            int sum = 0;
            
            for(int j = 0; j < arr[i].length(); j++){
                if(arr[i].charAt(j) == 'O'){
                    count ++;
                }else{
                    count = 0;
                }
                sum = sum + count;
            }
            sb.append(sum).append('\n');
        }
        System.out.print(sb);                       
    }
}

 

댓글