/ ALGORITHM

OX퀴즈

OX 퀴즈



import java.io.*;
import java.util.*;

public class Main{
    public static void main(String args[]) throws IOException {

        //1. List를 사용해서 동적배열로 입력받기
        //2. 저장된 문자열을 split로 문자로 구분후 문자열배열에 저장
        //3.O가 연속될때마다 값이 1증감되고 X를 만나면 다시 0에서 시작

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        List<Object> Array = new ArrayList<Object>();
        int n = Integer.parseInt(br.readLine());
        int count =0;
        int sum=0;

        //1.
        for(int i =0; i < n; i++) {
            Array.add(br.readLine());
        }

        //2.
        String[] str;
        for(Object aa : Array) {
            count =0;
            sum=0;
            str = (aa.toString()).split("");
        //3.
        for(String s : str) {
            if(s.equals("O")) {
            sum	+= ++count;
            } else {
            count =0;
            }
        }

        bw.write(sum +"\n");
        }

        br.close();
        bw.flush();
        bw.close();
    }
}

문제출처