웅재의 코딩세상

[프로그래머스] 공백으로 구분하기 1 본문

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

[프로그래머스] 공백으로 구분하기 1

웅드 2024. 1. 30. 16:45

 

 

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

using namespace std;

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