[백준] 8958번 : OX퀴즈 - JAVA(자바)

Life is ninanino·2022년 10월 17일
0

[백준] JAVA

목록 보기
19/37
post-thumbnail

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


이번 문제는 숫자가 아닌 String 값을 입력 받는다.
String 값을 배열에 하나씩 저장하기 위해선
split() 을 사용하거나 charAt()을 사용한다

++ 정답코드

package 백준;// @ author ninaaano

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

public class b_8958 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] arr = new String[n];

        for(int i=0; i<arr.length; i++){
            arr[i] = br.readLine();
        }
        br.close();
        for(int i=0; i<n; i++) {
            int cnt = 0;
            int sum = 0;
            for(int j=0; j<arr[i].length(); j++) {
                if (arr[i].charAt(j) == 'O') {
                    cnt++;
                } else
                    cnt = 0;
                sum += cnt;
            }
            System.out.println(sum);
        }
    }
}
profile
백엔드 프로그래밍을 공부하고 있습니다. AWS, 클라우드 환경에 대해 관심이 많습니다.

0개의 댓글