• PAT 1025 PAT Ranking


    1025 PAT Ranking

    Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.

    Input Specification:

    Each input file contains one test case. For each case, the first line contains a positive number N (≤100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.

    Output Specification:

    For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:

    registration_number final_rank location_number local_rank
    

    The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.

    Sample Input:

    1. 2
    2. 5
    3. 1234567890001 95
    4. 1234567890005 100
    5. 1234567890003 95
    6. 1234567890002 77
    7. 1234567890004 85
    8. 4
    9. 1234567890013 65
    10. 1234567890011 25
    11. 1234567890014 100
    12. 1234567890012 85

    Sample Output:

    1. 9
    2. 1234567890005 1 1 1
    3. 1234567890014 1 2 1
    4. 1234567890001 3 1 2
    5. 1234567890003 3 1 2
    6. 1234567890004 5 1 4
    7. 1234567890012 5 2 2
    8. 1234567890002 7 1 5
    9. 1234567890013 8 2 3
    10. 1234567890011 9 2 4

    总结:这道题不难,根据前面做过的几个差不多的结构体排序的问题,可以用差不多的方法做来,让我没有想到的是这次调试很快就调对了(很少T...T),还是挺高兴的,所以多练还是有用的!

    基本思路:在一开始输入的时候将每个地区的人排名一遍,然后根据分数赋上排名,最后总的排名一边,如果分数相等,那就按序号的高低排名(从低到高) 

    1. #include
    2. #include
    3. using namespace std;
    4. const int N=30010;
    5. struct Stu{
    6. string s;
    7. int score;
    8. int rank[3];//rank[0]表示全部排名,rank[1]表示地区,rank[2]表示当地排名
    9. }stu[N];
    10. bool cmp(Stu a,Stu b){
    11. return a.score>b.score;
    12. }
    13. bool cmp2(Stu a,Stu b){
    14. if(a.score!=b.score) return a.score>b.score;
    15. else return a.s
    16. }
    17. int main(){
    18. int n,k,sum=0,index=0;
    19. cin >> n;
    20. for(int i=0;i
    21. scanf("%d",&k);
    22. for(int j=0;j
    23. cin >> stu[index].s >> stu[index].score;
    24. stu[index++].rank[1]=i+1;
    25. }
    26. sort(stu+sum,stu+sum+k,cmp);
    27. stu[sum].rank[2]=1;
    28. for(int j=1;j
    29. stu[sum+j].rank[2]=j+1;
    30. if(stu[sum+j].score==stu[sum+j-1].score)
    31. stu[sum+j].rank[2]=stu[sum+j-1].rank[2];
    32. }
    33. sum+=k;
    34. }
    35. sort(stu,stu+sum,cmp2);
    36. stu[0].rank[0]=1;
    37. for(int j=1;j
    38. stu[j].rank[0]=j+1;
    39. if(stu[j].score==stu[j-1].score)
    40. stu[j].rank[0]=stu[j-1].rank[0];
    41. }
    42. printf("%d\n",sum);
    43. for(int i=0;i
    44. cout << stu[i].s << ' ' << stu[i].rank[0] << ' ' << stu[i].rank[1] << ' ' << stu[i].rank[2] << endl;
    45. }
    46. return 0;
    47. }

    依照惯例,还是看看大佬的!

    还是简洁明了,通俗易懂!(没有用cin cout 耗时少了很多)

    1. #include
    2. #include
    3. #include
    4. using namespace std;
    5. struct student {
    6. long long int no;
    7. int score, finrank, loca, locarank;
    8. };
    9. bool cmp1(student a, student b) {
    10. return a.score != b.score ? a.score > b.score : a.no < b.no;
    11. }
    12. int main() {
    13. int n, m;
    14. scanf("%d", &n);
    15. vector fin;
    16. for(int i = 1; i <= n; i++) {
    17. scanf("%d", &m);
    18. vector v(m);
    19. for(int j = 0; j < m; j++) {
    20. scanf("%lld %d", &v[j].no, &v[j].score);
    21. v[j].loca = i;
    22. }
    23. sort(v.begin(), v.end(), cmp1);
    24. v[0].locarank = 1;
    25. fin.push_back(v[0]);
    26. for(int j = 1; j < m; j++) {
    27. v[j].locarank = (v[j].score == v[j - 1].score) ? (v[j - 1].locarank) : (j + 1);
    28. fin.push_back(v[j]);
    29. }
    30. }
    31. sort(fin.begin(), fin.end(), cmp1);
    32. fin[0].finrank = 1;
    33. for(int j = 1; j < fin.size(); j++)
    34. fin[j].finrank = (fin[j].score == fin[j - 1].score) ? (fin[j - 1].finrank) : (j + 1);
    35. printf("%d\n", fin.size());
    36. for(int i = 0; i < fin.size(); i++)
    37. printf("%013lld %d %d %d\n", fin[i].no, fin[i].finrank, fin[i].loca, fin[i].locarank);
    38. return 0;
    39. }

    好好学习,天天向上!

    我要考研

    2022.11.2

    1. //思路很简单,在输入每一个地区的成绩时将地区成绩排名,然后把地区合并和在一个数组中
    2. //最后将数组中所有参赛者的成绩进行排名,打印结果即可
    3. #include
    4. #include
    5. #include
    6. using namespace std;
    7. struct node{
    8. string id;
    9. int f,loc,locrank,rank;
    10. };
    11. //获取排名
    12. bool cmp1(node a,node b){
    13. if(a.f!=b.f) return a.f>b.f;
    14. return a.id
    15. }
    16. int main(){
    17. int n,k,cot=0;
    18. scanf("%d",&n);
    19. vector v[n];
    20. for(int i=0;i
    21. scanf("%d",&k);
    22. cot+=k;
    23. string id;
    24. int f;
    25. v[i].resize(k);
    26. for(int j=0;j
    27. cin >> id >> f;
    28. v[i][j]={id,f,i+1};
    29. }
    30. sort(v[i].begin(),v[i].end(),cmp1);
    31. int pre=-1,rank=1;
    32. for(int j=0;j
    33. if(pre!=v[i][j].f) rank=j+1;
    34. v[i][j].locrank=rank;
    35. pre=v[i][j].f;
    36. }
    37. }
    38. vector s(300010);
    39. int t=0,pre=-1,rank=1;
    40. for(int i=0;i
    41. for(int j=0;jsize();j++)
    42. s[t++]=v[i][j];
    43. }
    44. printf("%d\n",t);
    45. sort(s.begin(),s.begin()+t,cmp1);
    46. for(int i=0;isize();i++){
    47. if(pre!=s[i].f) rank=i+1;
    48. s[i].rank=rank;
    49. pre=s[i].f;
    50. }
    51. for(int i=0;i
    52. cout << s[i].id;
    53. printf(" %d %d %d\n",s[i].rank,s[i].loc,s[i].locrank);
    54. }
    55. return 0;
    56. }

  • 相关阅读:
    Linux下的IMX6ULL——环境搭建与软件安装(一)
    CodeMirror 创建标签计算编辑器
    【Java集合】Collection接口常用方法
    计算机毕业设计Java紫陶文化传播与学习交流网站(源码+系统+mysql数据库+lw文档)
    【数据结构】树和二叉树的概念及结构(一)
    【MySQL】超详细-基础操作
    【DesignMode】组合模式(composite mode)
    Linux下实现U盘的挂载,复制文件和卸载等操作
    首个中文Stable Diffusion模型开源;TPU演进十年;18个PyTorch性能优化技巧 | AI系统前沿动态...
    如何使用远程控制软件并将用途最大化?4款国内外优质应用测评解析
  • 原文地址:https://blog.csdn.net/weixin_50679551/article/details/126838857