[PS 백준 - 1.1] 8958번: OX 퀴즈

4731 단어 백준psps

문제 정보

백준 8958번 - 바로가기

  • 난이도: 브론즈 2
  • 알고리즘: 문자열

코멘트

OX 채점결과를 문자열로 받은 뒤 str.length와 str[j]로 접근하여 점수를 더하는 형식으로 코드를 작성하였다.


소스 코드

#include <iostream>

using namespace std;

int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	std::ios::sync_with_stdio(false);

	int n, count = 1, total=0;
	cin >> n;
	string str;
	for (int i = 0; i < n; i++) {
		str.clear();
		cin >> str;
		for (int j = 0; j < str.length(); j++) {
			if (str[j] == 'O') {
				total += count++;
			}
			else {
				count = 1;
			}
		}
		cout << total << "\n";

		count = 1;
		total = 0;
	}
}

좋은 웹페이지 즐겨찾기