C++)
#include <iostream>
#include <string>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
string str;
cin >> str;
int answer = 0;
int temp = 0;
for (auto ch : str) {
if (ch == 'O') {
temp += 1;
}
else {
temp = 0;
}
answer += temp;
}
cout << answer << "\n";
}
return 0;
}
Python)
import sys
read = sys.stdin.readline
t = int(read().rstrip())
for _ in range(t):
result = read().rstrip()
answer = 0
temp = 0
for ch in result:
if ch == 'O':
temp += 1
else :
temp = 0
answer += temp
print(answer)
'백준 1 > 기초' 카테고리의 다른 글
| [백준 1152] 단어의 개수 (C++/Python) (0) | 2020.12.05 |
|---|---|
| [백준 10809] 알파벳 찾기 (C++/Python) (0) | 2020.12.05 |
| [백준 10818] 최소, 최대 (C++/Python) (0) | 2020.12.05 |
| [백준 11721] 열 개씩 끊어 출력하기 (C++/Python) (0) | 2020.12.05 |
| [백준 11720] 숫자의 합 (C++/Python) (0) | 2020.12.05 |