1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String[] arr = new String[scan.nextInt()];
// 입력받은 숫자만큼의 배열 길이 생성
for (int i=0; i<arr.length; i++) {
arr[i] = scan.next(); // nextLine()과 달리 개행문자 무시
int count = 0; // 중첩 카운트
int sum = 0; // 총 점수
for(int j=0; j<arr[i].length(); j++) {
if (arr[i].charAt(j) == 'O') {
count++; // 연속해서 O일 경우, 중첩
}
else {
count = 0; // X가 나올경우 중첩 초기화
}
sum += count;
}
System.out.println(sum);
}
}
}
|
cs |
'Algorithm > 백준' 카테고리의 다른 글
백준 4344 (평균은 넘겠지) (0) | 2022.06.30 |
---|---|
백준 10809 (알파벳 찾기) (0) | 2022.06.30 |
백준 1546 (평균) (0) | 2022.06.28 |
백준 3052 (나머지) (0) | 2022.06.28 |
백준 2577 (숫자의 개수) (0) | 2022.06.27 |