PTA 5-15 PAT Judge (25分)
2016-12-10 23:24
537 查看
/* * 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; }
相关文章推荐
- 5-15 PAT Judge (25分)
- PTA 7-15(查找) 航空公司VIP客户查询(25 分) 25分代码 哈希方法
- [PTA] 线性结构1 两个有序链表序列的合并(15 分)
- PTA 7-1 银行排队问题之单队列多窗口服务(25 分)25分代码 (小模拟)
- PTA 06-图2 Saving James Bond - Easy Version (25分)
- PTA-修理牧场(25分)
- pta 5-1 关于堆的判断 (25分)
- PTA 7-20(排序) 奥运排行榜(25 分) 25分代码 结构体排序
- PTA 5-12 How Long Does It Take (25分)
- PTA基础编程题目集7-19 支票面额(15 分)
- pta 5-6 列车调度 (25分)
- 【DFS】pta 5-12 功夫传人 (25分)
- PTA 数据结构与算法题目集(中文)5-4 是否同一棵二叉搜索树 (25分)
- 5-19 PAT Judge (25分)
- PTA 求前缀表达式的值 (25分)
- PTA 4-11 求自定类型元素序列的中位数 (25分)
- PTA 7-3 jmu-ds-单链表的基本运算(15 分)
- PTA-数据结构 5-18 银行业务队列简单模拟 (25分)
- PTA 5-19 列车厢调度 (25分)【stack】
- pta 5-3 红色警报 (25分) 并查集