백준
백준 소스코드 [C++] 10814 나이순 정렬
Hani_Levenshtein
2020. 9. 9. 15:24
10814번: 나이순 정렬
온라인 저지에 가입한 사람들의 나이와 이름이 가입한 순서대로 주어진다. 이때, 회원들을 나이가 증가하는 순으로, 나이가 같으면 먼저 가입한 사람이 앞에 오는 순서로 정렬하는 프로그램을 �
www.acmicpc.net
백준 소스코드 [C++] 10814 나이순 정렬
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
bool compare(pair<int, string>p1, pair<int, string>p2) {
return p1.first < p2.first;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n;
string s;
vector <pair<int, string>> v;
for (int i = 0;i < n;i++) {
cin >> m >> s;
v.push_back(make_pair(m, s));
}
stable_sort(v.begin(), v.end(), compare);
for (int i = 0;i < v.size();i++) cout << v[i].first << " " << v[i].second << '\n';
return 0;
}