-
[BOJ] 8958 :: OX퀴즈알고리즘/BOJ(C++) 2018. 6. 2. 21:20반응형
https://www.acmicpc.net/problem/8958
연속된 O의 개수를 찾는 것이 관건입니다.
X가 나오기 전까지 t의 값을 늘리면서 확인 해 주다 X가 나오면 t를 0으로 초기화 해주면 됩니다.
#include <iostream>#include <string>using namespace std;int main(){int t;cin >> t;while (t--){string s;cin >> s;int t = 0;int ans = 0;for (int i = 0; i < s.length(); i++){if (s[i] == 'O'){t++;ans += t;}else{t = 0;}}cout << ans << endl;}}댓글로 질문해주세요 :)반응형'알고리즘 > BOJ(C++)' 카테고리의 다른 글
[BOJ]1406 :: 에디터 (0) 2018.06.16 [BOJ] 6679 :: 싱기한 네자리 숫자 (0) 2018.06.02 [BOJ] 2581 :: 소수 (0) 2018.06.01 [BOJ]2908_상수 (0) 2018.06.01 [BOJ]10886_0 = not cute / 1 = cute (0) 2018.06.01