-
백준 10814: 나이순 정렬정렬(Sort) 2020. 11. 28. 18:26반응형
멀티맵(multimap)의 특성인 중복을 허용하면서 정렬 되는 점을 이용하여서 풀이
#include <iostream> #include <algorithm> // min #include <functional> #include <math.h> #include <string> #include <string.h> #include <vector> #include <map> #include <cmath> #include <sstream> #define M_PI 3.14159265358979323846 using namespace std; int main() { std::ios::sync_with_stdio(false); // 중복을 허용하면서 정렬이 되니 좋구먼 // 이문제가 맞은 이유는 입력은 가입한 순서로 주어지고 출력도 가입한 순서로 나오면 되기 때문에 multimap<int, string> m; int n; cin >> n; while (n--) { int d; cin >> d; string s; cin >> s; m.insert(pair<int, string>(d, s)); } multimap<int, string>::iterator iter; for (iter = m.begin(); iter != m.end(); iter++) { cout << iter->first << " " << iter->second << "\n"; } return 0; }
반응형'정렬(Sort)' 카테고리의 다른 글
백준 10989: 수 정렬하기 3 (0) 2020.11.28 백준 11650: 좌표 정렬하기 (0) 2020.11.28 백준 1427번: 소트인사이트 (0) 2020.11.28 백준 9946번: 단어 퍼즐 (0) 2018.07.23 백준 2947번: 나무 조각 (1) 2018.07.16