[백준 14592] 2017 아주대학교 프로그래밍 경시대회 (Small) (C#, C++) - soo:bak
작성일 :
문제 링크
14592번 - 2017 아주대학교 프로그래밍 경시대회 (Small)
설명
참가자 정보를 점수 내림차순, 제출 횟수 오름차순, 마지막 업로드 시간 오름차순으로 비교해 가장 높은 순위의 참가자 번호를 출력합니다. 참가자는 최대 3명입니다.
접근법
참가자 구조체에 번호와 (점수, 제출, 시간)을 담아 정렬 기준을 위 순서대로 지정합니다.
정렬 후 첫 원소의 번호가 1등이므로 그대로 출력합니다.
Code
C#
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
using System;
using System.Collections.Generic;
class Program {
struct Player {
public int s, c, l, idx;
}
static int Compare(Player a, Player b) {
if (a.s != b.s) return b.s.CompareTo(a.s);
if (a.c != b.c) return a.c.CompareTo(b.c);
return a.l.CompareTo(b.l);
}
static void Main() {
int n = int.Parse(Console.ReadLine()!);
var list = new List<Player>();
for (int i = 0; i < n; i++) {
var parts = Array.ConvertAll(Console.ReadLine()!.Split(), int.Parse);
list.Add(new Player { s = parts[0], c = parts[1], l = parts[2], idx = i + 1 });
}
list.Sort(Compare);
Console.WriteLine(list[0].idx);
}
}
C++
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
#include <bits/stdc++.h>
using namespace std;
struct Player {
int s, c, l, idx;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
if (!(cin >> n)) return 0;
vector<Player> v(n);
for (int i = 0; i < n; i++) {
v[i].idx = i + 1;
cin >> v[i].s >> v[i].c >> v[i].l;
}
sort(v.begin(), v.end(), [](const Player& a, const Player& b) {
if (a.s != b.s) return a.s > b.s;
if (a.c != b.c) return a.c < b.c;
return a.l < b.l;
});
cout << v[0].idx << "\n";
return 0;
}