#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
struct student{
int id, grade = 0, perfect_solution = 0;
bool valid = false;
bool questions[5];//记录是否提交过
};
bool comp(student a, student b){
if(a.grade != b.grade)
return a.grade > b.grade;
if(a.perfect_solution != b.perfect_solution)
return a.perfect_solution > b.perfect_solution;
if(a.valid != b.valid)
return a.valid;
return a.id < b.id;
}
int main()
{
int N, K, M;
cin>>N>>K>>M;
int scores[5];
int submittion[10000][5];
memset(submittion, -2, sizeof(int)*50000);
vector<student> students(N);
for(int i = 0; i < K; i++)
cin>>scores[i];
for(int i = 0; i < M; i++){
int st, question, score;
scanf("%d %d %d", &st, &question, &score);
st--;
question--;
submittion[st][question] = max(submittion[st][question], score);
students[st].questions[question] = true;
}
for(int i = 0; i < N; i++){
students[i].id = i;
for (int j = 0; j < K; j++){
if(students[i].questions[j] && submittion[i][j] >= 0)
{
students[i].grade += submittion[i][j];
students[i].valid = true;
}
if(students[i].questions[j] && submittion[i][j] == scores[j])
students[i].perfect_solution ++;
}
}
sort(students.begin(), students.end(), comp);
int current_grade = 0, current_rank = 0, real_rank = 0;
for(auto itr = students.begin(); itr != students.end(); itr++)
{
if (!itr -> valid)
return 0;
real_rank ++;
if(itr -> grade != current_grade){
current_grade = itr -> grade;
current_rank = real_rank;
}
printf("%d %05d %d", current_rank, itr->id + 1, itr->grade);
for(int i = 0; i < K; i++){
if (itr-> questions[i])
printf(" %d", max(submittion[itr->id][i], 0));
else
printf(" -");
}
printf("\n");
}
}
用LUA(和C++)刷PAT (Advanced Level) ——1075 PAT Judge
最新推荐文章于 2024-11-12 21:33:25 发布
该程序实现了一个学生评分系统,读取学生分数、提交情况及满分标准,然后根据成绩、满分解决方案数量和提交的有效性对学生进行排序。排序依据为成绩、满分解决方案数和ID。最后输出排名、学生ID、成绩以及每个问题的得分或未提交标记。
摘要由CSDN通过智能技术生成