https://www.acmicpc.net/problem/10825
10825번: 국영수
첫째 줄에 도현이네 반의 학생의 수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 한 줄에 하나씩 각 학생의 이름, 국어, 영어, 수학 점수가 공백으로 구분해 주어진다. 점수는 1보다 크거나 같고, 100보다 작거나 같은 자연수이다. 이름은 알파벳 대소문자로 이루어진 문자열이고, 길이는 10자리를 넘지 않는다.
www.acmicpc.net
정렬로 분류된 10825 - 국영수 문제 입니다.
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _10825
{
class Program
{
public class Student : IComparable, IComparer<string>
{
public string Name;
public int Language;
public int English;
public int Math;
public Student(string[] input)
{
this.Name = input[0];
this.Language = int.Parse(input[1]);
this.English = int.Parse(input[2]);
this.Math = int.Parse(input[3]);
}
public int CompareTo(Object obj)
{
Student other = obj as Student;
if(this.Language == other.Language)
{
if(this.English == other.English)
{
{
}
}
return this.English.CompareTo(other.English);
}
return other.Language.CompareTo(this.Language);
}
public int Compare(string s1, string s2)
{
for(int i = 0; i < length; i++)
{
if(s1[i] == s2[i]){
continue;
}
if (char.IsUpper(s1[i]) && !char.IsUpper(s2[i]))
return -1;
else if (char.IsUpper(s2[i]) && !char.IsUpper(s1[i]))
return 1;
else
return s1[i].CompareTo(s2[i]);
}
return s1.CompareTo(s2);
}
}
static void Main(string[] args)
{
int count = int.Parse(Console.ReadLine());
var studentList = new List<Student>();
for(int i = 0; i < count; i++)
{
}
Console.WriteLine("{0}", studentList[i].Name);
}
}
}
|
이 문제는 푸는 방법을 안다면 하지 않으시는걸 추천합니다.
마지막 이름을 사전순으로 비교하는 경우 C#에서는 소문자가 앞으로 오게 됩니다.
그래서 이름 비교를 위한 함수를 따로 만들어 줬습니다.
그 외에는 일반 정렬 방법과 동일합니다.
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
정렬 방법 입니다.
백준#11652 - 카드 (0) | 2020.04.29 |
---|---|
백준#3047 - ABC (0) | 2020.04.21 |
백준#11004 - K번째 수 (0) | 2020.04.20 |
백준#11651 - 좌표 정렬하기 2 (0) | 2020.04.20 |
백준#10814 - 나이순 정렬 (0) | 2020.04.20 |