https://www.acmicpc.net/problem/11650
정렬로 분류된 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
백준#11651 - 좌표 정렬하기 2 (0) | 2020.04.20 |
---|---|
백준#10814 - 나이순 정렬 (0) | 2020.04.20 |
백준#1181 - 단어 정렬 (0) | 2020.04.20 |
백준#1026 - 보물 (0) | 2020.04.20 |
백준#1427 - 소트인사이드 (0) | 2020.04.19 |