From ac5810ed501c3c02e207d841fb606071614fba90 Mon Sep 17 00:00:00 2001 From: hao14293 Date: Sun, 4 Aug 2019 00:02:02 +0800 Subject: [PATCH] =?UTF-8?q?Create=201012=20The=20Best=20Rank=20(25=20?= =?UTF-8?q?=E5=88=86).cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PAT/PAT-A/CPP/1012 The Best Rank (25 分).cpp | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 PAT/PAT-A/CPP/1012 The Best Rank (25 分).cpp diff --git a/PAT/PAT-A/CPP/1012 The Best Rank (25 分).cpp b/PAT/PAT-A/CPP/1012 The Best Rank (25 分).cpp new file mode 100644 index 0000000..4081d84 --- /dev/null +++ b/PAT/PAT-A/CPP/1012 The Best Rank (25 分).cpp @@ -0,0 +1,52 @@ +#include +#include +using namespace std; + +struct node{ + int id, best; + int score[4], rank[4]; +}stu[2005]; +int exist[1000000], flag = -1; +bool cmp1(node 1, node b){ + return a.score[flag] > b.score[flag]; +} + +int main(){ + int n, m, id; + cin >> n >> m; + for(int i = 0; i < n; i++){ + cin >> stu[i].id >> stu[i].score[1] >> stu[i].score[2] >> stu[i].score[3]; + stu[i].score[0] = (stu[i].score[1] + stu[i].score[2] + stu[i].score[3]) / 3.0 + 0.5; + } + for(flag = 0; flag <= 3; flag++){ + sort(stu, stu + n, cmp1); + stu[0].rank[flag] = 1; + for(int i = 1; i < n; i++){ + stu[i].rank[flag] = i + 1; + if(stu[i].score[flag] == stu[i-1].score[flag]) + stu[i].rank[flag] = stu[i-1].rank[flag]; + } + } + for(int i = 0; i < n; i++){ + exist[stu[i].id] = i + 1; + stu[i].best = 0; + int minn = stu[i].rank[0]; + for(int j = 1; j <= 3; j++){ + if(stu[i].rank[j] < minn){ + minn = stu[i].rank[j]; + stu[i].best = j; + } + } + } + char c[5] = {'A', 'C', 'M', 'E'}; + for(int i = 0; i < m; i++){ + cin >> id; + int temp = exist[id]; + if(temp){ + int best = stu[temp-1].best; + printf("%d %c\n", stu[temp-1].rank[best], c[best]); + }else + printf("N/A\n"); + } + return 0; +}