728x90
반응형
delim이 string
#include <bits/stdc++.h>
using namespace std;
vector<string> split(const string& input, const string& delim) {
vector<string> res;
auto start = 0;
auto end = input.find(delim);
while (end != string::npos) {
res.push_back(input.substr(start, end - start));
start = end + delim.size();
end = input.find(delim, start);
}
res.push_back(input.substr(start));
return res;
}
delim이 char
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
string s;
int main() {
getline(cin, s);
stringstream ss(s);
string buffer;
while (getline(ss, buffer, ' ')) {
cout << buffer << endl;
}
cout << endl;
return 0;
}
delim 이 공백이고 앞에 공백 있을 때
#include <bits/stdc++.h>
using namespace std;
string s;
int res = 0;
int main() {
getline(cin, s);
stringstream ss(s);
string buffer;
while (ss >> buffer) {
res++;
}
cout << res;
return 0;
}
728x90
'자질구레' 카테고리의 다른 글
[Linux] "Warning: The unit file, source configuration file or drop-ins of XXX.service changed on disk. Run 'systemctl daemon-reload' to reload units." (0) | 2025.01.30 |
---|---|
맥북 시간 이상할 때 (1) | 2024.12.15 |
시간복잡도, Big O, 점근적 표기법 (0) | 2024.12.12 |
vscode code 명령어 사라짐 해결 (mac) (0) | 2024.11.09 |
[Kubernetes] bitnami/mysql startup probe failed 문제 (0) | 2024.11.03 |