Baekjoon Algorithm | Problem 8958: OX Quiz
Source
https://www.acmicpc.net/problem/8958
Problem
Solve Baekjoon Online Judge problem 8958, OX Quiz.
Input
Follow the input format and constraints given in the original problem statement.
Output
Print the answer required by the problem.
Sample Input 1
5 OOXXOXXOOO OOXXOOXXOO OXOXOXOXOXOXOX OOOOOOOOOO OOOOXOOOOXOOOOX
Sample Output 1
10 9 7 55 30
Solution
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
int n = Integer.parseInt(br.readLine());
int[] sums = new int[n];
for (int i = 0; i < n; i++) {
String oxLine = br.readLine();
int sum = 0;
int score = 1;
for(int j=0; j < oxLine.length(); j++) {
char ox = oxLine.charAt(j);
if (ox == 'O') {
sum += score;
score++;
} else {
score = 1;
}
}
sums[i] = sum;
}
for (int sum : sums) {
System.out.println(sum);
}
}
}
}