C# | 백준 | 8958

Algorithm 2019. 10. 11. 10:43
반응형

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

 

8958번: OX퀴즈

문제 "OOXXOXXOOO"와 같은 OX퀴즈의 결과가 있다. O는 문제를 맞은 것이고, X는 문제를 틀린 것이다. 문제를 맞은 경우 그 문제의 점수는 그 문제까지 연속된 O의 개수가 된다. 예를 들어, 10번 문제의 점수는 3이 된다. "OOXXOXXOOO"의 점수는 1+2+0+0+1+0+0+1+2+3 = 10점이다. OX퀴즈의 결과가 주어졌을 때, 점수를 구하는 프로그램을 작성하시오. 입력 첫째 줄에 테스트 케이스의 개수가 주어진다. 각 테스트 케이스는

www.acmicpc.net

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _8958
{
    class Program
    {
        static void Main(string[] args)
        {
            var length = int.Parse(Console.ReadLine());
            string[] arr = new string[length];
            for (int i = 0; i < length; i++) {
                arr[i] = Console.ReadLine();
            }
 
            
            foreach (var str in arr) {
                int score = 0;
                int elapsedScore = 0;
                //Console.WriteLine(str);
                var arrChar = str.ToCharArray();
                for (int i = 0; i < arrChar.Length; i++) {
                    if (arrChar[i] == 'O')
                    {
                        score += 1;
                    }
                    else {
                        score = 0;
                    }
                    elapsedScore += score;
                }
                Console.WriteLine(elapsedScore);
            }
        }
    }
}
 
 
 
반응형

'Algorithm' 카테고리의 다른 글

C# | 백준 | 2577  (0) 2019.10.15
C# | 백준 | 1546  (0) 2019.10.15
C# | 백준 | 2920  (0) 2019.10.10
프로그래머스 | 기지국 설치  (0) 2019.09.06
프로그래머스 | 최소공배수  (0) 2019.09.06
: