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
'Coding Test > 백준' 카테고리의 다른 글
[백준 10809번 - java] 알파벳 찾기 (0) | 2021.11.14 |
---|---|
[백준 11720번 - java] 숫자의 합 (0) | 2021.11.13 |
[백준 11654번 - java] 아스키 코드 (0) | 2021.11.12 |
[백준 4344번 - java] 평균은 넘겠지 (0) | 2021.11.12 |
[백준 1546번 - java] 평균 (0) | 2021.11.12 |