๋ฐ์ํ
vector<string> split(const string &str) {
vector<string> tokens;
string::size_type start = 0;
string::size_type end = 0;
while ((end = str.find(" ", start)) != string::npos) {
tokens.push_back(str.substr(start, end - start));
start = end + 1;
}
tokens.push_back(str.substr(start));
return tokens;
}โ
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
void printArray(vi &ary, int size) {
int i=0;
cout << '[';
for (const auto &each : ary) {
cout << each;
(i++ !=size-1)? cout<<',':cout<<']';
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
vi v = {1,5,9,7,3,6,4,2,8};
sort(v.rbegin(), v.rend());
printArray(v, v.size());
v.pop_back();
v.pop_back();
printArray(v, v.size());
for (int i=0; i<10; i++) {
random_shuffle(v.begin(), v.end());
printArray(v, v.size());
}
vpi vp;
vp.push_back({1, 5});
vp.push_back({2, 3});
vp.push_back({1, 2});
vp.push_back({3, 4});
vp.push_back({6, 3});
sort(vp.begin(), vp.end());
return 0;
}
C++ String split
๋ฐ์ํ
'๐ฅ Computer Science > Programming' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[์๊ณ ๋ฆฌ์ฆ] ๋ฐฑ์ค 16236 ์๊ธฐ์์ด (0) | 2020.08.23 |
---|---|
[C++] ์ ๋ ฌ (Sorting) (0) | 2019.10.19 |
[C++] ํ๋ก๊ทธ๋๋ฐ์ ์ํ ํ ํ๋ฆฟ (Cheat sheet) (0) | 2019.10.05 |