본문 바로가기
category/백준 알고리즘 c++

백준 알고리즘 8958번 OX퀴즈 c++

by 자운대고라니 2021. 1. 20.
반응형

요약 : 케이스 값 입력 후 케이스 수만큼 O와X를 번갈아가면서 넣는다. O가 연속으로 있을시에는 중복으로 1점씩 추가하고, X가 나오면 다시 O가 1점으로 바뀐다.


소스코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <cstring>
 
using namespace std;
 
int main(void) {
    int C;
    cin >> C;
    while(C--) {
        int count = 0,result = 0;
        char array[81= {0,};
        cin >> array;
        for(int i=0;i<strlen(array);i++) {
            if(array[i]=='O') {
                count++;
                result += count;
            }
            else {
                count = 0;
            }
        }
        cout << result << endl;
    }
    return 0;
}
 
cs

 


정답 확인

 

반응형

댓글