T = int(input())
listed_OX =[input() for _ in range(T)]
for OX in listed_OX:
total_sum = 0
X_split = OX.split('X')
for correct in X_split:
n = len(correct)
if(n > 0):
total_sum += (n * (n+1)) // 2
print(total_sum)
+ 정규표현식 re module 사용
import re
T = int(input())
listed_OX = [input() for _ in range(T)]
p = re.compile('O+')
for OX in listed_OX:
total_sum = 0
X_split = p.findall(OX)
for ele in X_split:
n = len(ele)
total_sum += (n * (n+1)) // 2
print(total_sum)
'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글
Baekjoon 10039번(python) (0) | 2019.04.28 |
---|---|
Baekjoon 2920번(python) (0) | 2019.04.28 |
Baekjoon 2577번(python) (0) | 2019.04.28 |
Baekjoon 1152번(python) (0) | 2019.04.28 |
Baekjoon 2448번(python) (2) | 2019.04.28 |