Koder / 박성훈
article thumbnail

얘도 머 바로 전 글과 별반 다를게 없다.

설명은 바로전글 가서 들어도 될 거 같다.

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

 

11651번: 좌표 정렬하기 2

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

www.acmicpc.net

#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;
struct POS{ int x; int y; };// 가입순서 - 나이 - 이름 
vector<POS> v; 

bool compare(POS a, POS b){
	if(a.y != b.y) return a.y < b.y;
	else return a.x < b.x;
}

int main(){
	int n;
	scanf("%d", &n);
	v.resize(n);
	for(int i=0; i<n; i++) scanf("%d %d",&v[i].x, &v[i].y);
	
	sort(v.begin(), v.end(), compare);
	
	for(int i=0; i<n; i++) printf("%d %d\n", v[i].x, v[i].y);
	return 0;
}

이것도 무난하게 AC.

반응형