백준 8958

Hyerin·2022년 1월 15일
0
post-thumbnail

문제

https://www.acmicpc.net/problem/8958

C# 풀이

using System;
using System.IO;

namespace baekjoon
{
    class Program
    {
        static void Main(string[] args)
        {
            // 표준 입출력 스트림 reader,writer 만들기
            // 첫째 줄에 테스트 케이스의 개수 입력받기, int로 바꾸기
            // 둘째 줄부터 OX퀴즈의 결과 입력받기
            // 점수 계산하기
            // 버퍼에 저장
            // 버퍼 한 번에 비우기

            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

            string strTestCase = sr.ReadLine();
            int nTestCase = int.Parse(strTestCase);

            int nCount = 0;
            int nScore = 0;

            for (int i = 0; i < nTestCase; i++) // 5
            {
                string strQuizResult = sr.ReadLine(); // "OOXXOXXOOO"

                for (int j = 0; j < strQuizResult.Length; j++)
                {
                    // 문자열은 문자배열이다.
                    if (strQuizResult[j] == 'O')
                    {
                        nCount += 1; 
                    }
                    else
                    {
                        nCount = 0; 
                    }

                    nScore += nCount; 
                }

                sw.WriteLine(nScore);
                nCount = 0;
                nScore = 0;
            }

            sw.Flush();
            sr.Close();
            sw.Close();
        }
    }
}

0개의 댓글