#include <iostream>
#include <vector>
#include <string>
#include <algorithm> // std::stable_sort
using namespace std;
bool compare(pair<int, string> a, pair<int, string> b){
//if(a.first == b.first) return a.second > b.second; // 나이 같을 경우, 먼저 가입한 a가 앞에
return a.first < b.first; // default: 나이 증가하는 순 정렬
}
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);
int N; cin >> N;
vector<pair<int, string>> v;
for(int i=0; i<N; i++){
int x; string y;
cin >> x >> y;
v.push_back({x,y});
}
stable_sort(v.begin(), v.end(), compare);
for(auto result: v) cout << result.first << " " << result.second << "\n";
}
#include <iostream>
#include <vector>
#include <string>
#include <algorithm> // std::stable_sort
using namespace std;
class solution{
public:
int age;
string name;
solution(int a, string b){ age = a; name = b; }
};
bool compare(solution a, solution b){
//if(a.age == b.age) return a.second > b.second; // 나이 같을 경우, 먼저 가입한 a가 앞에
return a.age < b.age; // default: 나이 증가하는 순 정렬
}
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);
int N; cin >> N;
vector<solution> v;
for(int i=0; i<N; i++){
int x; string y;
cin >> x >> y;
v.push_back(solution(x,y));
}
stable_sort(v.begin(), v.end(), compare);
for(auto result: v) cout << result.age << " " << result.name << "\n";
}
[백준(BOJ)] 11004번: K번째 수 (정렬, C++) (0) | 2021.08.04 |
---|---|
[백준(BOJ)] 10825번: 국영수 (정렬, C++) (0) | 2021.03.10 |
[백준(BOJ)] 11650번: 좌표 정렬하기 (정렬, C++) (0) | 2021.03.10 |
[백준(BOJ)] 11651번: 좌표 정렬하기 2 (정렬, C++) (0) | 2021.03.10 |
[백준(BOJ)] 15552번: 빠른 A+B (C++) (0) | 2021.03.10 |