728x90
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
31
32
33
34
35
|
import java.util.Scanner;
public class B8958 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int testNum = scanner.nextInt();
//더할 값
int plus = 0;
//결과
int result = 0;
for (int i = 0; i < testNum; i++) {
//입력할 OX 값
String testCase = scanner.next();
//문자열을 문자 배열로 변환
char[]ox = testCase.toCharArray();
//문자 배열 길이만큼 반복
for (int j = 0; j < ox.length; j++) {
//O이면 plus를 1씩 올리면서 결과에 더해줌
if (ox[j]=='O') {
plus++;
result+=plus;
//X이면 plus를 0으로 초기화
}else if(ox[j]=='X'){
plus = 0;
}
}
System.out.println(result);
//한번의 반복이 끝나면 결과와 plus 초기화
result=0;
plus=0;
}
scanner.close();
}
}
|
cs |
728x90
'백준' 카테고리의 다른 글
백준 2798 - 블랙잭 (0) | 2022.05.16 |
---|---|
백준 4344 - 평균은 넘겠지 (0) | 2022.05.11 |
백준 1546 - 평균 (0) | 2022.05.11 |
백준 3052 - 나머지 (0) | 2022.05.11 |
백준 2675 - 문자열 반복 (0) | 2022.05.11 |