首页 > 代码库 > PTA 5-15 PAT Judge (25分)
PTA 5-15 PAT Judge (25分)
/* * 1.主要就用了个sort对结构体的三级排序 */ #include "iostream" #include "algorithm" using namespace std; int perfectScore[6]; struct Node { int id; int score[6] = {-2,-2,-2,-2,-2,-2}; /* 记录每一题的分数 初始化为-2代表没答题 */ int totalScore = 0; /* 记录总分 */ int perfectSolvedNum = 0; /* 记录得满分的题目总数 */ bool flag = false; /* 判断该用户能否上ranklist 默认不能 */ }stu[10001]; int comp(const Node &stu1, const Node &stu2) { if (stu1.totalScore == stu2.totalScore) { if (stu1.perfectSolvedNum == stu2.perfectSolvedNum) return stu1.id < stu2.id; else return stu1.perfectSolvedNum > stu2.perfectSolvedNum; } else return stu1.totalScore > stu2.totalScore; } void getMSG(Node stu[10001],int n,int k) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { if(stu[i].score[j]>=0) stu[i].totalScore += stu[i].score[j]; if (stu[i].score[j] >= 0) stu[i].flag = true; if (stu[i].score[j] == -1) stu[i].score[j] = 0; if (stu[i].score[j] == perfectScore[j]) stu[i].perfectSolvedNum += 1; } } } int main() { int n, m, k; cin >> n >> k >> m; for (int i = 1; i <= k; i++) cin >> perfectScore[i]; while (m--) { int stuId, proId, score; cin >> stuId >> proId >> score; stu[stuId].id = stuId; if (score > stu[stuId].score[proId]) stu[stuId].score[proId] = score; } getMSG(stu, n, k); sort(stu+1,stu+n+1,comp); int l = 0; int temp = stu[1].totalScore; int rank = 1; for (int i = 1; i <= n; i++) { if (stu[i].flag) { if (stu[i].totalScore == temp) l++; else { rank += l; l = 1; temp = stu[i].totalScore; } cout << rank << " "; printf("%05d ", stu[i].id); cout << stu[i].totalScore; for (int j = 1; j <= k; j++) { if (stu[i].score[j] == -2) cout << " -"; else cout << " " << stu[i].score[j]; } cout << endl; } } return 0; }
PTA 5-15 PAT Judge (25分)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。