코딩테스트/프로그래머스 - LV 0
[프로그래머스] 코드 처리하기
웅드
2024. 1. 24. 23:01
- 풀이
#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;
}
반응형