알고리즘/BOJ(C++)
[BOJ] 8958 :: OX퀴즈
쿠마쿠마34
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;}}댓글로 질문해주세요 :)
반응형