오늘은 무슨 정렬의 날인거 같다. 신난다. 이거야말로 진짜 아까 구현해놓은거랑 비슷해서 고대로 가져다가 사용했는데 이게 되네 ㅋㅋㅋ 나이스! 코드를 이해하고 싶다면 BOJ.1181번 풀어놓은걸 참고하자.
# include "iostream"
# include "algorithm"
using namespace std;
class hello{
public:
string name;
int age;
int surro;
};
bool compare (hello a, hello b){
if (a.age != b.age){
return a.age < b.age;
}
else{
return a.surro < b.surro;
}
};
int main(void){
int N;
hello arr[100000];
cin >> N;
for (int i = 0; i < N; i++){
cin >> arr[i].age >> arr[i].name;
arr[i].surro = i;
}
sort(arr, arr + N, compare);
for (int i = 0; i < N; i++){
cout << arr[i].age << " " << arr[i].name << "\n";}
return 0;
}