https://www.acmicpc.net/problem/10814
정렬로 분류된 10814 - 나이순 정렬 문제 입니다.
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _10814
{
class Program
{
public class Register : IComparable
{
public static int Indexer;
public int Index;
public int Age;
public string Name;
public Register(string name, int age)
{
this.Age = age;
this.Name = name;
this.Index = Register.Indexer++;
}
public int CompareTo(Object obj)
{
Register other = obj as Register;
}
}
static void Main(string[] args)
{
int count = int.Parse(Console.ReadLine());
Register.Indexer = 0;
var RegisterList = new List<Register>();
for (int i = 0; i < count; i++)
{
string[] strRegister = Console.ReadLine().Split(' ');
}
foreach (var r in RegisterList)
Console.WriteLine("{0} {1}", r.Age, r.Name);
}
}
}
|
Register라는 클래스 정의 후 IComparable을 상속받아 CompareTo를 구현했습니다.
Sort후 출력 했습니다. 먼저 온 순서를 알기 위해 static int Indexer를 뒀습니다.
Sort방법
https://programming-mr.tistory.com/46
백준#11004 - K번째 수 (0) | 2020.04.20 |
---|---|
백준#11651 - 좌표 정렬하기 2 (0) | 2020.04.20 |
백준#11650 - 좌표 정렬하기 (0) | 2020.04.20 |
백준#1181 - 단어 정렬 (0) | 2020.04.20 |
백준#1026 - 보물 (0) | 2020.04.20 |