728x90
https://school.programmers.co.kr/learn/courses/30/lessons/181932
소스코드
using System;
public class Solution
{
public string solution(string code)
{
string answer = "";
string mode = "0";
for (int i = 0; i < code.Length; i++)
{
if (code[i] == '1' || code[i] == '0')
{
mode = mode == "1" ? "0" : "1";
continue;
}
if (mode == "0" && i % 2 == 0)
answer += code[i].ToString();
else if (mode == "1" && i % 2 == 1)
answer += code[i].ToString();
}
if (string.IsNullOrEmpty(answer))
answer = "EMPTY";
return answer;
}
}
728x90
'코딩공부 > 프로그래머스' 카테고리의 다른 글
[프로그래머스]Lv.0 마지막 두 원소 C# (0) | 2023.06.02 |
---|---|
[프로그래머스]Lv.0 이어 붙인 수 C# (0) | 2023.06.02 |
[프로그래머스]Lv.0 원소들의 곱과 합 C# (0) | 2023.06.02 |
[프로그래머스]Lv.0 주사위 게임 2 C# (0) | 2023.06.02 |
[프로그래머스]Lv.0 등차수열의 특정한 항만 더하기 C# (0) | 2023.06.02 |