반응형
#include <vector>
#include <sstream>
#include <iosteam>
#include <string>
int solution(vector<string> lines) {
stringstream ss;
vector<vector<string> > v;
for(int i=0; i<lines.size(); i++){
ss.str(lines[i]);
string tmp;
while(ss >> tmp){
v[i].push_back(tmp);
cout << v[i].back() << "\n";
}
cout << "-----";
}
}
/*
ex) 입력 : ["하이 방가", "오늘 뭐해?"]
출력 : "하이"
"방가"
-----
"오늘"
"뭐해?"
*/
함수로 구현
#include <vector>
#include <sstream>
#include <string>
vector<string> split(string str, char delimiter) {
stringstream ss(str);
string tmp;
vector<string> v;
while (getline(ss, tmp, delimiter)) {
v.push_back(tmp);
}
return v;
}
int solution(vector<string> lines) {
vector<vector<string> > v;
for(int i=0; i<lines.size(); i++){
v.push_back( split(lines[i], ' ') );
}
return answer;
}
반응형