알고리즘

백준 : : 11650번 좌표 정렬하기 - C++ 풀이

green333 2022. 1. 24. 14:22
728x90
SMALL

https://www.acmicpc.net/problem/11650

 

11650번: 좌표 정렬하기

첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에는 i번점의 위치 xi와 yi가 주어진다. (-100,000 ≤ xi, yi ≤ 100,000) 좌표는 항상 정수이고, 위치가 같은 두 점은 없다.

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
vector<pair<intint>> axis;
 
int main(){
  int num;
  cin >> num;
  int x, y;
 
  for(int i = 0; i < num; i++){
  cin >> x >> y;
  axis.push_back({x, y});
  }
  sort(axis.begin(), axis.end());
  for(int i = 0; i < num; i++){
    cout << axis[i].first << " " << axis[i].second << "\n";
  }
  return 0;
}
 
cs

 

std::endl과 \n의 차이
std::endl은 버퍼를 비울때, \n는 버퍼를 비우지 않을때 (더 빠름)
즉시 출력해줘야하는 게 아니라면 \n으로 모아뒀다가 출력하는게 시간을 줄일 수 있다.

 

참조 블로그

https://yechoi.tistory.com/48

 

[C++] std::endl이 \n과 다른 점 - 출력버퍼 이해하기

C++ 시작하는 친구가 문득 std::endl이랑 '\n'이랑 뭐가 다르냐고 물었다. 이전에 훑어보기론 std::endl 은 출력버퍼를 비우고 \n 은 그렇지 않다고 봐, 이렇게 설명을 해줬다. 그랬더니 버퍼가 뭐냐, 버

yechoi.tistory.com

 

LIST