dh-winternagi 님의 블로그
(11650) 좌표 정렬하기 본문
https://www.acmicpc.net/problem/11650
단계별로 풀어보기
13단계(정렬) 7번째
C++의 pair나 tuple 구조체는 기본적으로 첫 번째 요소부터 순차적으로 오름차순 비교하는 정렬 함수를 갖고 있어서 바로 정렬함수를 사용할 수 있다.

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<pair<int,int>> v(n);
for(int i=0;i<n;i++) cin >> v[i].first >> v[i].second;
sort(v.begin(), v.end());
for(int i=0;i<n;i++) cout << v[i].first << " " << v[i].second << "\n";
return 0;
}'백준 (C++) > Solve' 카테고리의 다른 글
| (1181) 단어 정렬 (0) | 2026.04.14 |
|---|---|
| (11651) 좌표 정렬하기 2 (0) | 2026.04.14 |
| (1427) 소트인사이드 (0) | 2026.04.13 |
| (10989) 수 정렬하기 3 (0) | 2026.04.13 |
| (2751) 수 정렬하기 2 (0) | 2026.04.13 |
