C#/알고리즘
백준#11650 - 좌표 정렬하기
McRobbin
2020. 4. 20. 12:20
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
정렬로 분류된 11650 좌표 정렬하기 문제 입니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _11650
{
class Program
{
public class Pair : IComparable
{
public int x;
public int y;
public Pair(int x, int y)
{
this.x = x;
this.y = y;
}
public int CompareTo(Object obj)
{
Pair other = obj as Pair;
if (this.x == other.x)
return this.y.CompareTo(other.y);
return this.x.CompareTo(other.x);
}
}
static void Main(string[] args)
{
int count = int.Parse(Console.ReadLine());
var PairList = new List<Pair>();
for(int i = 0; i < count; i++)
{
string[] pair = Console.ReadLine().Split(' ');
}
foreach (Pair pair in PairList)
Console.WriteLine("{0} {1}", pair.x, pair.y);
}
}
}
|
Pair라는 클래스 생성후 IComparable 상속받아 CompareTo 정의 했습니다.
정렬 방법 입니다.
https://programming-mr.tistory.com/46
C# List Sort예제.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69..
programming-mr.tistory.com