-
[백준 / C#] 11650 좌표 정렬하기C#/Coding Test 2024. 11. 18. 16:27
문제
2차원 평면 위의 점 N개가 주어진다. 좌표를 x좌표가 증가하는 순으로, x좌표가 같으면 y좌표가 증가하는 순서로 정렬한 다음 출력하는 프로그램을 작성하시오.
입력
첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에는 i번점의 위치 xi와 yi가 주어진다. (-100,000 ≤ xi, yi ≤ 100,000) 좌표는 항상 정수이고, 위치가 같은 두 점은 없다.
출력
첫째 줄부터 N개의 줄에 점을 정렬한 결과를 출력한다.
나의 풀이
int n = int.Parse(Console.ReadLine()); List<(int, int)> list = new List<(int, int)>(); for(int i = 0; i < n; i++) { int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); list.Add((input[0], input[1])); } var sortedlist = list.OrderBy(x => x.Item1).ThenBy(x => x.Item2).ToList(); for(int j = 0; j < n; j++) Console.WriteLine(sortedlist[j].Item1 + " " + sortedlist[j].Item2);
출처
https://www.acmicpc.net/problem/11650
'C# > Coding Test' 카테고리의 다른 글
[백준 / C#] 10989 수 정렬하기 3 (1) 2024.11.27 [Programmers / C#] 스택/큐 다리를 지나는 트럭 (1) 2024.11.15 [Programmers / C#] 연습문제 호텔 대실 (0) 2024.11.14