-
[백준 Class 2] 10814 나이순 정렬 C++ 풀이C++/백준 2023. 1. 16. 18:11728x90
https://www.acmicpc.net/problem/10814
10814번: 나이순 정렬
온라인 저지에 가입한 사람들의 나이와 이름이 가입한 순서대로 주어진다. 이때, 회원들을 나이가 증가하는 순으로, 나이가 같으면 먼저 가입한 사람이 앞에 오는 순서로 정렬하는 프로그램을
www.acmicpc.net
문제 링크입니다.
난이도는 실버5로 자료구조를 알고있느냐의 정도로 보시면 될 것 같습니다.
key = 나이
value = 회원 이름으로 선택하여 풀었고 key에 중복이 허용되어야 하므로 multimap을 사용했습니다.
#include <iostream> #include <string> #include <utility> #include <iterator> #include <map> using namespace std; multimap<int, string> member; multimap<int, string>::iterator it; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N; cin >> N; for (int i = 0; i < N; i++) { int a; string b; cin >> a >> b; member.insert(make_pair(a, b)); } for (auto it = member.begin(); it != member.end(); it++) { cout << it->first << " " << it->second << '\n'; } }
728x90'C++ > 백준' 카테고리의 다른 글
[백준 Class 2] 11650 좌표 정렬하기 C++ 풀이 (0) 2023.01.16 [백준 Class 2] 1181번 단어 정렬 C++ 풀이 (2) 2022.12.21 [백준 Class 2] 1018번 체스판 C++ 풀이 (0) 2022.12.21 [백준 Class 2] 2798번 블랙잭 C++ 풀이 (0) 2022.12.20 [백준 Class 2] 10250번 ACM 호텔 C++ 풀이 (0) 2022.12.20