웅재의 코딩세상
[프로그래머스] 코드 처리하기 본문
- 풀이
#include <string>
#include <vector>
using namespace std;
string solution(string code) {
string answer = "";
bool mode = true;
for(int i=0; i<code.size(); i++){
if(code[i] == '1') mode = !mode;
else if(mode == true && i % 2 == 0){
answer += code[i];
}
else if(mode == false && i % 2 == 1){
answer += code[i];
}
}
if(empty(answer)) return "EMPTY";
return answer;
}
반응형
'코딩테스트 > 프로그래머스 - LV 0' 카테고리의 다른 글
[프로그래머스] 접두사인지 확인하기 (0) | 2024.01.24 |
---|---|
[프로그래머스] 등차수열의 특정한 항만 더하기 (0) | 2024.01.24 |
[프로그래머스] 주사위 게임 2 (1) | 2024.01.24 |
[프로그래머스] 이어 붙인 수 (0) | 2024.01.24 |
[프로그래머스] 원소들의 곱과 합 (0) | 2024.01.23 |