프로그래머스 181867 x 사이의 개수

1 개요[ | ]

프로그래머스 181867 x 사이의 개수

2 C++[ | ]

#include <string>
#include <vector>
#include <sstream>
using namespace std;

vector<int> solution(string myString) {
    vector<int> answer;
    int len = 0;
    for(char ch: myString) {
        if(ch == 'x') {
            answer.emplace_back(len);
            len = 0;
        } else {
            len++;
        }
    }
    answer.emplace_back(len);
    return answer;
}
#include <string>
#include <vector>
#include <sstream>
using namespace std;

vector<int> solution(string myString) {
    vector<int> answer;
    istringstream ss(myString);
    for (string s; getline(ss, s, 'x'); ) {
        answer.push_back(s.length());
    }
    if(myString[myString.length()-1] == 'x') {
        answer.push_back(0);
    }
    return answer;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}