PTA 5-15 PAT Judge (25分)

时间:2023-03-09 09:55:41
PTA 5-15 PAT Judge   (25分)
/*
* 1.主要就用了个sort对结构体的三级排序
*/ #include "iostream"
#include "algorithm"
using namespace std;
int perfectScore[];
struct Node {
int id;
int score[] = {-,-,-,-,-,-}; /* 记录每一题的分数 初始化为-2代表没答题 */
int totalScore = ; /* 记录总分 */
int perfectSolvedNum = ; /* 记录得满分的题目总数 */
bool flag = false; /* 判断该用户能否上ranklist 默认不能 */
}stu[];
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[],int n,int k) {
for (int i = ; i <= n; i++) {
for (int j = ; j <= k; j++) {
if(stu[i].score[j]>=)
stu[i].totalScore += stu[i].score[j];
if (stu[i].score[j] >= )
stu[i].flag = true;
if (stu[i].score[j] == -)
stu[i].score[j] = ;
if (stu[i].score[j] == perfectScore[j])
stu[i].perfectSolvedNum += ;
}
}
}
int main() {
int n, m, k;
cin >> n >> k >> m;
for (int i = ; 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+,stu+n+,comp);
int l = ;
int temp = stu[].totalScore;
int rank = ;
for (int i = ; i <= n; i++) {
if (stu[i].flag) {
if (stu[i].totalScore == temp)
l++;
else {
rank += l;
l = ;
temp = stu[i].totalScore;
}
cout << rank << " ";
printf("%05d ", stu[i].id);
cout << stu[i].totalScore;
for (int j = ; j <= k; j++) {
if (stu[i].score[j] == -)
cout << " -";
else
cout << " " << stu[i].score[j];
}
cout << endl;
}
}
return ;
}