Published 2020. 12. 29. 05:18
 

8958번: OX퀴즈

"OOXXOXXOOO"와 같은 OX퀴즈의 결과가 있다. O는 문제를 맞은 것이고, X는 문제를 틀린 것이다. 문제를 맞은 경우 그 문제의 점수는 그 문제까지 연속된 O의 개수가 된다. 예를 들어, 10번 문제의 점수

www.acmicpc.net

#include <iostream>
#include <string>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

	int t; cin >> t; cin.ignore();
	while (t--) {
		string str; getline(cin, str); str += "\n";
		int cnt = 0;
		int score = 0;
		for (size_t i = 0; i < str.size(); i++) {
			if (str[i] == 'O') {
				++cnt;
				score += cnt;
			}
			else if (str[i] == 'X' || str[i] == '\n') {
				cnt = 0;
			}
		}
		cout << score << "\n";
	}

	return 0;
}

'Problem set' 카테고리의 다른 글

[백준] 9093: 단어 뒤집기  (0) 2020.12.29
[백준] 9012: 괄호  (0) 2020.12.29
[백준] 6588: 골드바흐의 추측  (0) 2020.12.29
[백준] 4673: 셀프넘버  (0) 2020.12.29
[백준] 3052: 나머지  (0) 2020.12.29
복사했습니다!