题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805393241260032

题意:

有m次OJ提交记录,总共有k道题,n个人。每道题有一个最高分。

现在要统计用户的排名,如果总分相同,完整AC的题目数高的排前面,都一样id小的排前面。

如果没有提交记录,或者提交记录都是-1的用户,就不输出。

思路:

根据题意模拟。PAT的题目都要耐心好好读题啊,各种情况都要看清楚。

 #include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue> #define inf 0x7fffffff
using namespace std;
typedef long long LL;
typedef pair<string, string> pr; int n, k, m;
int sco[];
const int maxn = 1e4 + ;
struct node{
bool print = false;
int id;
int s[] = {-, -, -, -, -, -, -};
int sum = ;
int num = ;
}user[maxn]; bool cmp(node a, node b)
{
if(a.sum == b.sum){
if(a.num == b.num)return a.id < b.id;
return a.num > b.num;
}
return a.sum > b.sum;
} int main()
{
scanf("%d%d%d", &n, &k, &m);
for(int i = ; i <= k; i++){
scanf("%d", &sco[i]);
}
for(int i = ; i <= n; i++){
user[i].id = i;
}
for(int i = ; i <= m; i++){
string id;
int pro, s;
cin>>id>>pro>>s;
int iid = stoi(id);
if(s != -)user[iid].print = true;
if(user[iid].s[pro] == -){
if(s == -)user[iid].s[pro] = ;
else user[iid].s[pro] = s;
user[iid].sum += user[iid].s[pro];
if(user[iid].s[pro] == sco[pro])user[iid].num++;
}
else if(user[iid].s[pro] < s){
user[iid].sum += s - user[iid].s[pro];
user[iid].s[pro] = s;
if(user[iid].s[pro] == sco[pro])user[iid].num++;
}
}
sort(user + , user + + n, cmp);
int rnk = ;
for(int i = ; i <= n; i++){
if(!user[i].print)continue;
if(user[i].sum != user[i - ].sum)rnk = i;
printf("%d %05d %d", rnk, user[i].id, user[i].sum);
for(int j = ; j <= k; j++){
if(user[i].s[j] != -)printf(" %d", user[i].s[j]);
else printf(" -");
}
printf("\n");
} return ;
}
05-08 15:36