Algorithm/백준
백준 8958 (OX퀴즈)
leecom116
2022. 6. 28. 23:24
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 |