Problem
There is an objective test result such as “OOXXOXXOOO”. An ‘O’ means a correct answer of a problem and an ‘X’ means a wrong answer. The score of each problem of this test is calculated by itself and its just previous consecutive ‘O’s only when the answer is correct. For example, the score of the 10th problem is 3 that is obtained by itself and its two previous consecutive ‘O’s.
Therefore, the score of “OOXXOXXOOO” is 10 which is calculated by “1+2+0+0+1+0+0+1+2+3”.
You are to write a program calculating the scores of test results.
Input
Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case starts with a line containing a string composed by ‘O’ and ‘X’ and the length of the string is more than 0 and less than 80. There is no spaces between ‘O’ and ‘X’.
Output
Your program is to write to standard output. Print exactly one line for each test case. The line is to contain the score of the test case.
example input 1
5
OOXXOXXOOO
OOXXOOXXOO
OXOXOXOXOXOXOX
OOOOOOOOOO
OOOOXOOOOXOOOOX
output 1
10
9
7
55
30
Line 1, Line 2 is the area that how many times you will run this codes.
n = int(input())
for i in range(n):
ox_list is input area, you can input 'example input' in here it can be used Line 6.
Line 4 and Line 5 will help you to count how many 'O' and 'X' in ox_list
ox_list = list(input())
sum = 0
sum_real = 0
'for ox in ox_list' it work that if you input 'OOX' then 'ox_list' will give 'ox' the it's value.
for example => 'ox' will receive 'O' at the first, 'O' in second, and last is 'X'
for ox in ox_list:
if ox == 'O':
sum += 1
sum_real += sum
else:
sum = 0
if 'O' in ox, sum will be +1, and same work in sum_real. if there is 'O' string in a row 'sum' will receive one more +1 and this will give 'sum_real' +2
else: will reset 'sum' when 'X' data is appeared in ox.
n = int(input())
for i in range(n):
ox_list = list(input())
sum = 0
sum_real = 0
for ox in ox_list:
if ox == 'O':
sum += 1
sum_real += sum
else:
sum = 0
print(sum_real)
'백준' 카테고리의 다른 글
[백준/Python3] 3052번: 나머지 (0) | 2022.04.17 |
---|---|
[백준/Python3] 15552번: 빠른 A+B (0) | 2022.04.17 |
[백준/Python3] 2562번: 최댓값 (0) | 2022.04.17 |
[백준/Python3] 11720번: 숫자의 합 (1) | 2022.04.15 |
[백준/Python3] 2523 번: 별 찍기 - 13 (0) | 2022.04.14 |