题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805393241260032
题意:
有m次OJ提交记录,总共有k道题,n个人。每道题有一个最高分。
现在要统计用户的排名,如果总分相同,完整AC的题目数高的排前面,都一样id小的排前面。
如果没有提交记录,或者提交记录都是-1的用户,就不输出。
思路:
根据题意模拟。PAT的题目都要耐心好好读题啊,各种情况都要看清楚。
1 #include<cstdio> 2 #include<cstdlib> 3 #include<map> 4 #include<set> 5 #include<iostream> 6 #include<cstring> 7 #include<algorithm> 8 #include<vector> 9 #include<cmath> 10 #include<stack> 11 #include<queue> 12 13 #define inf 0x7fffffff 14 using namespace std; 15 typedef long long LL; 16 typedef pair<string, string> pr; 17 18 int n, k, m; 19 int sco[7]; 20 const int maxn = 1e4 + 5; 21 struct node{ 22 bool print = false; 23 int id; 24 int s[7] = {-1, -1, -1, -1, -1, -1, -1}; 25 int sum = 0; 26 int num = 0; 27 }user[maxn]; 28 29 bool cmp(node a, node b) 30 { 31 if(a.sum == b.sum){ 32 if(a.num == b.num)return a.id < b.id; 33 return a.num > b.num; 34 } 35 return a.sum > b.sum; 36 } 37 38 int main() 39 { 40 scanf("%d%d%d", &n, &k, &m); 41 for(int i = 1; i <= k; i++){ 42 scanf("%d", &sco[i]); 43 } 44 for(int i = 1; i <= n; i++){ 45 user[i].id = i; 46 } 47 for(int i = 1; i <= m; i++){ 48 string id; 49 int pro, s; 50 cin>>id>>pro>>s; 51 int iid = stoi(id); 52 if(s != -1)user[iid].print = true; 53 if(user[iid].s[pro] == -1){ 54 if(s == -1)user[iid].s[pro] = 0; 55 else user[iid].s[pro] = s; 56 user[iid].sum += user[iid].s[pro]; 57 if(user[iid].s[pro] == sco[pro])user[iid].num++; 58 } 59 else if(user[iid].s[pro] < s){ 60 user[iid].sum += s - user[iid].s[pro]; 61 user[iid].s[pro] = s; 62 if(user[iid].s[pro] == sco[pro])user[iid].num++; 63 } 64 } 65 sort(user + 1, user + 1 + n, cmp); 66 int rnk = 1; 67 for(int i = 1; i <= n; i++){ 68 if(!user[i].print)continue; 69 if(user[i].sum != user[i - 1].sum)rnk = i; 70 printf("%d %05d %d", rnk, user[i].id, user[i].sum); 71 for(int j = 1; j <= k; j++){ 72 if(user[i].s[j] != -1)printf(" %d", user[i].s[j]); 73 else printf(" -"); 74 } 75 printf(" "); 76 } 77 78 return 0; 79 }