백준 8958 - OX퀴즈

황재진·2024년 3월 7일

백준

목록 보기
18/54
post-thumbnail

문자열을 입력받아 'O'와 'X'일 때를 체크해 더할 점수를 판별하면 되는 문제입니다.

#include <iostream>

int main()
{
	int n;
	std::cin >> n;

	char str[81];
	for (int i = 0; i < n; i++)
	{
		std::cin >> str;

		int len = 0; // 문자열 길이
		while (str[len] != '\0')
			len++;
		
		int score = 0;
		int scoremult = 1;
		for (int i = 0; i < len; i++)
		{
			if (str[i] == 'O')
			{
				score += scoremult;
				scoremult++;
			}
			else if(str[i] == 'X')
				scoremult = 1;
		}
		std::cout << score << "\n";
	}	

	return 0;
}
profile
프로그래밍, 쉐이더 등 이것저것 다해보는 게임 개발자입니다

0개의 댓글