728x90
코드
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
struct A {
int age;
string name;
};
int main() {
vector<A> list;
int n, temp;
string str;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp >> str;
A a = { temp, str };
list.push_back(a);
}
stable_sort(list.begin(), list.end(), [](const A& a, const A& b) {return a.age < b.age; });
for (int i = 0; i < n; i++) {
cout << list[i].age << ' ' << list[i].name << "\n";
}
}
문제 링크 : https://www.acmicpc.net/problem/10814
728x90
'알고리즘 > C++ - 백준' 카테고리의 다른 글
[백준/BOJ](c++/cpp) 2751번 수 정렬하기 2 (0) | 2024.08.16 |
---|---|
[백준/BOJ](c++/cpp) 1676번 팩토리얼 0의 개수 (0) | 2024.08.16 |
[백준/BOJ](c++/cpp) 28702번 FizzBuzz (0) | 2024.08.13 |
[백준/BOJ](c++/cpp) 11050번 이항 계수 1 (0) | 2024.08.13 |
[백준/BOJ](c++/cpp) 10989번 수 정렬하기 3 (0) | 2024.08.13 |