본문 바로가기
Coding Test/백준

[백준 8958번 - java ] OX퀴즈

by olli2 2021. 11. 13.

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

 

내 답안

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] arr = new String[s.nextInt()];
		
		for (int i=0; i<arr.length; i++) {
			
			char c = 0;
			int cnt = 1;
			int total = 0;
			arr[i] = s.next();
			
			for (int j=0; j<arr[i].length(); j++) {
				c = arr[i].charAt(j);
				if (c == 'O') total += cnt++;
				else cnt = 1;
			}
			System.out.println(total);
		}
	}
}

 

Scanner 클래스의 next()와 nextInt() 차이점 때문에 한참 헤맸다.

https://dotddori-prgmwh.tistory.com/84