//1025. PAT Ranking (25)
//acc
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
typedef struct
{
char name[14];
int score;
int index;
}Student;
bool cmp( Student stu1, Student stu2)
{
if (stu1.score == stu2.score)
{
return strcmp(stu1.name , stu2.name) < 0;
}
return stu1.score > stu2.score;
}
int main()
{
int N;
cin >> N;
int i;
Student stu[30001];
int Index[101];
int j;
int start = 0;
int total = 0;
for (i=0;i<N;i++)
{
//cin >> Index[i];
scanf("%d", &Index[i]);
for (j = start;j<Index[i]+start; j++)
{
scanf("%s %d", stu[j].name, &stu[j].score);
stu[j].index = i+1;
}
start += Index[i];
total += Index[i];
}
cout << total << endl;
sort(stu, stu+total, cmp);
int curr[101];
fill(curr, curr + 101, 1);
int pre = -20;
int premingci = 1;
int mingci;
int arr[101];
fill(arr, arr + 101, -1);
int arrpre[101];
fill(arrpre, arrpre + 101, -1);
for (i = 0;i< total;i++)
{
if(pre == stu[i].score)
{
mingci = premingci;
}
else
{
mingci = i+1;
pre = stu[i].score;
premingci = mingci;
}
cout << stu[i].name << " " << mingci << " " << stu[i].index << " ";
if (arr[ stu[i].index ] == -1 || stu[i].score != arr[stu[i].index])
{
cout << curr[ stu[i].index ]<< endl;
arr[stu[i].index] = stu[i].score;
arrpre[stu[i].index] = curr[stu[i].index];
curr[stu[i].index]++;
}
else
{
cout << arrpre[stu[i].index] << endl;
curr[stu[i].index]++;
}
}
return 0;
}PAT 1025. PAT Ranking (25)
最新推荐文章于 2024-05-22 12:35:49 发布
本篇博客介绍了一个名为PATRanking的成绩排名系统的设计与实现。该系统使用C++编程语言,通过结构体存储学生信息,并利用自定义比较函数进行成绩排序。系统能够处理多个批次的数据输入,支持按分数和姓名顺序对学生进行排名,并输出每个学生的排名信息及所在批次的相对位置。
282

被折叠的 条评论
为什么被折叠?



