λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
Algorithm πŸ§‘πŸ»‍πŸ’»/λ°±μ€€(BOJ)

[λ°±μ€€,c++] 10814번 - λ‚˜μ΄μˆœ μ •λ ¬

by dkswnkk 2021. 10. 24.
 

10814번: λ‚˜μ΄μˆœ μ •λ ¬

온라인 저지에 κ°€μž…ν•œ μ‚¬λžŒλ“€μ˜ λ‚˜μ΄μ™€ 이름이 κ°€μž…ν•œ μˆœμ„œλŒ€λ‘œ 주어진닀. μ΄λ•Œ, νšŒμ›λ“€μ„ λ‚˜μ΄κ°€ μ¦κ°€ν•˜λŠ” 순으둜, λ‚˜μ΄κ°€ κ°™μœΌλ©΄ λ¨Όμ € κ°€μž…ν•œ μ‚¬λžŒμ΄ μ•žμ— μ˜€λŠ” μˆœμ„œλ‘œ μ •λ ¬ν•˜λŠ” ν”„λ‘œκ·Έλž¨μ„

www.acmicpc.net

#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

bool cmp(pair<int,string>x ,pair<int,string>y) {
    return (x.first < y.first);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<pair<int, string>> v(N);

    for (int i = 0; i < N; i++) {
        cin >> v[i].first >> v[i].second;
    }
    stable_sort(v.begin(), v.end(), cmp);

    for (int i = 0; i < N; i++) {
        cout << v[i].first << " " << v[i].second << "\n";
    }

}

λŒ“κΈ€