웅재의 코딩세상

[프로그래머스] 세 개의 구분자 본문

코딩테스트/프로그래머스 - LV 0

[프로그래머스] 세 개의 구분자

웅드 2024. 2. 1. 21:01

 

  • 풀이
#include <string>
#include <vector>

using namespace std;

vector<string> solution(string myStr) {
    vector<string> answer;
    string s;
    for(int i=0; i<myStr.size(); i++){
        if(myStr[i]=='a' || myStr[i]=='b' || myStr[i]=='c'){
            if(!s.empty()) {
                answer.push_back(s);
                s="";
            }
        } 
        else s += myStr[i];
    }
    if(!s.empty()) answer.push_back(s);
    if(answer.empty()) answer.push_back("EMPTY");
    return answer;
}
반응형