#include <string>
#include <vector>
using namespace std;
string solution(string code) {
string ret = "";
//mode 0 : code[idx] !=1 / idx가 짝수일때만 ret 맨뒤 code[idx]추가
//mode 0 : code[idx] ==1 / mode0을 1로 변경
//mode 1 : code[idx] !=1 / idx가 홀수일때만 ret 맨뒤 code[idx]추가
//mode 1 : code[idx] ==1 / mode1을 0로 변경
bool mode = false;
//0~code의 길이-1 까지 반복
for(int idx=0; idx<code.length(); idx++)
{
if(!mode)
{
if(code[idx] != '1')
{
if(idx%2==0)
ret += code[idx];
}
else if((int)code[idx])
mode = true;
}
else
{
if(code[idx] != '1')
{
if(idx%2==1)
ret += code[idx];
}
else if((int)code[idx])
mode = false;
}
}
if(ret.length() == 0)
return "EMPTY";
return ret;
}
'C++' 카테고리의 다른 글
| [프로그래머스] 주사위 게임 2 (1) | 2025.08.28 |
|---|---|
| [프로그래머스] 등차수열의 특정한 항만 더하기 (3) | 2025.08.28 |
| [프로그래머스] flag에 따라 다른 값 반환하기 (0) | 2025.08.28 |
| [프로그래머스] 조건 문자열 (1) | 2025.08.28 |
| [프로그래머스] 공배수 (0) | 2025.08.27 |
댓글