Skip to content

Commit beaa7ad

Browse files
committed
[Silver V] Title: 좌표 정렬하기 2, Time: 172 ms, Memory: 73764 KB -BaekjoonHub
1 parent 5dcc455 commit beaa7ad

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# [Silver V] 좌표 정렬하기 2 - 11651
2+
3+
[문제 링크](https://www.acmicpc.net/problem/11651)
4+
5+
### 성능 요약
6+
7+
메모리: 73764 KB, 시간: 172 ms
8+
9+
### 분류
10+
11+
정렬
12+
13+
### 제출 일자
14+
15+
2026년 2월 9일 19:49:26
16+
17+
### 문제 설명
18+
19+
<p>2차원 평면 위의 점 N개가 주어진다. 좌표를 y좌표가 증가하는 순으로, y좌표가 같으면 x좌표가 증가하는 순서로 정렬한 다음 출력하는 프로그램을 작성하시오.</p>
20+
21+
### 입력
22+
23+
<p>첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에는 i번점의 위치 x<sub>i</sub>와 y<sub>i</sub>가 주어진다. (-100,000 ≤ x<sub>i</sub>, y<sub>i</sub> ≤ 100,000) 좌표는 항상 정수이고, 위치가 같은 두 점은 없다.</p>
24+
25+
### 출력
26+
27+
<p>첫째 줄부터 N개의 줄에 점을 정렬한 결과를 출력한다.</p>
28+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
let N = Int(readLine()!)!
2+
var matrix = [(x: Int, y: Int)]()
3+
4+
for _ in 0..<N {
5+
let input = readLine()!.split(separator: " ").map { Int($0)! }
6+
7+
matrix.append((input[0], input[1]))
8+
}
9+
10+
matrix.sort {
11+
if $0.y == $1.y {
12+
return $0.x < $1.x
13+
}
14+
return $0.y < $1.y
15+
}
16+
17+
var result = ""
18+
19+
for p in matrix {
20+
result += "\(p.x) \(p.y)\n"
21+
}
22+
23+
print(result)

0 commit comments

Comments
 (0)