๐ฉ๐ปProgramming/Coding Test
[C#] [BOJ#8958] OXํด์ฆ - ToCharArray
taesooya
2022. 7. 30. 23:42
https://www.acmicpc.net/problem/8958
2741๋ฒ: N ์ฐ๊ธฐ
์์ฐ์ N์ด ์ฃผ์ด์ก์ ๋, 1๋ถํฐ N๊น์ง ํ ์ค์ ํ๋์ฉ ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
www.acmicpc.net
My Solution
๋๋ ๊ณต๋ฐฑ ์๋ ๋ฌธ์์ด์ ์ด๋ป๊ฒ ๋ฐฐ์ด๋ก ๋ง๋๋ ๊ณ ๋ฏผํ๋๋ฐ ์ด๋ด ๋ ToCharArray
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int t = int.Parse(Console.ReadLine());
for (int i = 0; i < t; i++)
{
int sum = 0;
int count = 0;
string s = Console.ReadLine();
~~char[] chars = s.ToCharArray();~~
for (int j = 0; j < chars.Length; j++)
{
if (chars[j] != 'X')
{
count++;
sum += count;
}
else
{
count = 0;
}
}
Console.WriteLine(sum);
}
}
}
}
Solution
using System;
class Program {
static void Main()
{
int n = int.Parse(Console.ReadLine());
string[] testCase = new string[n];
for (int i = 0; i < n; i++)
{
testCase[i] = Console.ReadLine();
char[] temp = testCase[i].ToCharArray();
int j = 0;
int resultScore = 0;
int score = 0;
while (true)
{
if(temp[j].ToString() == "O")
{
score++;
resultScore += score;
}
else
{
score = 0;
}
j++;
if (j == temp.Length) break;
}
Console.WriteLine(resultScore);
}
}
}