【PAT甲级】1075. PAT Judge (25)
来源:互联网 发布:linux 查看登陆用户 编辑:程序博客网 时间:2024/06/05 02:19
注意:如果一名同学提交代码未通过编译,则他这道题成绩打印为0;如果他对某一题从未提交过代码,则他这道题成绩打印为‘-’;如果他提交的所有代码均未通过编译,则不打印他的成绩单。
#include <stdio.h>#include <vector>#include <stdlib.h>#include <string.h>#include <algorithm>using namespace std;struct Stu{ int id; int total; int perfect;};int sco_mat[1000000][6];int n, k, m;void print_score(Stu s);bool cmp(Stu a, Stu b);int main() { scanf("%d %d %d", &n, &k, &m); int *p = new int[k + 1]; for (int i = 1; i <= k; i++) { scanf("%d", &p[i]); } int uid, pid, score; memset(sco_mat, -1, sizeof(sco_mat)); vector<Stu> v; while (m) { scanf("%d %d %d", &uid, &pid, &score); if (sco_mat[uid][0] == -1) { if (score >= 0) { //给此学生建档 sco_mat[uid][0] = 1; Stu s; s.id = uid; s.total = -1; sco_mat[uid][pid] = score; v.push_back(s); } else if (score == -1) {//编译不通过,并不建档 sco_mat[uid][pid] = 0; } } else if (sco_mat[uid][pid] <= score) { sco_mat[uid][pid] = score; if (score == -1) sco_mat[uid][pid] = 0; } m--; } for (int i = 0; i < v.size(); i++) { int sum = 0; int perfect = 0; for (int j = 1; j <= k; j++) { if (sco_mat[v[i].id][j] != -1) { sum += sco_mat[v[i].id][j]; } if (sco_mat[v[i].id][j] == p[j]) perfect++; } v[i].total = sum; v[i].perfect = perfect; } if (v.size() == 0) return 0; sort(v.begin(), v.end(), cmp); int rank = 1; printf("1 "); print_score(v[0]); int pre = 1; for (int i = 1; i < v.size(); i++) { if (v[i].total == v[i - 1].total) { printf("%d ", rank); pre++; } else { printf("%d ", rank += pre); pre = 1; } print_score(v[i]); } return 0;}void print_score(Stu s) { printf("%05d ", s.id); printf("%d ", s.total); for (int i = 1; i <= k; i++) { if (sco_mat[s.id][i] == -1) printf("-"); else printf("%d", sco_mat[s.id][i]); if (i < k) printf(" "); } printf("\n"); return;}bool cmp(Stu a, Stu b) { if (a.total > b.total) return true; else if (a.total == b.total && a.perfect > b.perfect) return true; else if (a.total == b.total && a.perfect == b.perfect && a.id < b.id) return true; return false;}
阅读全文
0 0
- 1075. PAT Judge (25) PAT甲级
- PAT甲级.1075. PAT Judge (25)
- 【PAT甲级】1075. PAT Judge (25)
- PAT 甲级 1075. PAT Judge (25)
- 1075. PAT Judge (25)-PAT甲级真题
- 未完成-PAT甲级练习1075. PAT Judge (25)
- PAT 1075. PAT Judge (25)
- PAT 1075. PAT Judge (25)
- 【PAT】1075. PAT Judge (25)
- 1075. PAT Judge (25)
- 1075. PAT Judge (25)
- 1075. PAT Judge (25)
- 1075. PAT Judge (25)
- 1075. PAT Judge (25)
- 1075. PAT Judge (25)
- 1075. PAT Judge (25)
- 1075. PAT Judge (25)
- 1075. PAT Judge (25)
- 基于vue.js的分页插件
- C# WinForm窗口最小化到系统托盘右击托盘图标弹出退出菜单
- [总结]FFMPEG视音频编解码零基础学习方法
- 深入理解C语言的函数调用过程
- Unity DES AES加密数据 序列化和反序列化 通用方法
- 【PAT甲级】1075. PAT Judge (25)
- echarts之tooltip-trigger
- 【ShareSDK】Unity3d 使用ShareSDK 做安卓分享
- HashSet的实现
- Linux 通配符 及特殊字符 $、\、`、
- Selenium学习笔记19-操作控件设置高亮
- 一次完整的自动化测试-2017-7-4
- 第一次的博客
- Unity RSA 加密数据 序列化和反序列化 通用方法