๏ฃฟ Apple Lover Developer & Artist

์˜์†์ ์ธ ๋””์ž์ธ์— ํ˜„๋Œ€์˜ ๊ณต๊ฐ์„ ์ฑ„์›Œ๋„ฃ๋Š” ๊ณต๋ฐฉ์ž…๋‹ˆ๋‹ค

๐Ÿ–ฅ Computer Science/Programming

[C++] ๋ณด๊ด€ํ•จ

singularis7 2019. 10. 19. 17:06
๋ฐ˜์‘ํ˜•
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

 

๋ฐ˜์‘ํ˜•