题目描述
大 模 拟
(其实也没多大qwq
慢慢写 注意细节就可以啦
C++ 代码
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, k, m;
int full_score[6];
struct S
{
bool is_exist = false;
int total_score, rank, id;
int score[6];
bool submit[6] = {0};
bool operator<(S &a)
{
if (total_score != a.total_score) return total_score > a.total_score;
int cnt1 = 0, cnt2 = 0;
for (int i = 1; i <= k; i ++)
{
if (full_score[i] == score[i]) cnt1 ++;
if (full_score[i] == a.score[i]) cnt2 ++;
}
if (cnt1 != cnt2) return cnt1 > cnt2;
return id < a.id;
}
}s[10010];
int len(int n)
{
int c = 0;
do c ++, n /= 10; while (n);
return c;
}
void get_rank(vector<S>& a)
{
if (a.size() == 0) return;
a[0].rank = 1;
for (int i = 1; i < a.size(); i ++)
if (a[i].total_score == a[i - 1].total_score) a[i].rank = a[i - 1].rank;
else a[i].rank = i + 1;
}
int main()
{
cin >> n >> k >> m;
for (int i = 1; i <= k; i ++) cin >> full_score[i];
for (int i = 0; i < m; i ++)
{
int user_id, problem_id, score;
cin >> user_id >> problem_id >> score;
s[user_id].id = user_id;
if (score != -1) s[user_id].is_exist = true;
if (score == -1) score = 0;
s[user_id].score[problem_id] = max(s[user_id].score[problem_id], score);
s[user_id].submit[problem_id] = true;
}
vector<S> u;
for (int i = 0; i < 10010; i ++)
if (s[i].is_exist)
{
for (int j = 1; j <= k; j ++)
s[i].total_score += s[i].score[j];
u.push_back(s[i]);
}
sort(u.begin(), u.end());
get_rank(u);
for (int i = 0; i < u.size(); i ++)
{
cout << u[i].rank << " ";
int l = len(u[i].id);
for (int j = 0; j < 5 - l; j ++) cout << "0";
cout << u[i].id << " ";
cout << u[i].total_score << " ";
for (int j = 1; j <= k; j ++)
{
if (u[i].submit[j])
cout << u[i].score[j] << " ";
else cout << "- ";
}
cout << endl;
}
}