PAT:1025. PAT Ranking (25) 编辑错误

#include<stdio.h>
#include<algorithm>
using namespace std;
struct Student
{
  char ID[15];
  int score,final_rank,location_number,local_rank;  //分数,总排名,考场号,场内排名
}STU[30010];

bool cmp(Student a, Student b)
{
  if(a.score!=b.score)
    return a.score>b.score;      //按分数从大到小
  else
    return strcmp(a.ID,b.ID)<0;    //按字典序从小到大
}

int main()
{
  int n,I=0;            //I记录所有STU学生个数
  scanf("%d",&n);
  for(int t=1 ; t<=n ; ++t)    //n个考场
  {
    int k;
    scanf("%d",&k);
    for(int i=0 ; i<k ; ++i)
    {
      scanf("%s %d",&STU[I+i].ID, &STU[I+i].score);  //记录ID,分数
      STU[I+i].location_number=t;            //记录考场号
    }
    sort(STU+I,STU+I+k,cmp);
    STU[I].local_rank=1;
    for(int i=1 ; i<k ; ++i)              //记录场内排名
    {
      if(STU[I+i].score==STU[I+i-1].score)
        STU[I+i].local_rank=STU[I+i-1].local_rank;  //和前一个同学名次相同
      else
        STU[I+i].local_rank=i+1;          //否则排名为i+1
    }
    I+=k;                      //到下一个考场,I从k个考生之后开始算
  }
  sort(STU,STU+I,cmp);
  STU[0].final_rank=1;
  for(int i=1 ; i<I ; ++i)              //总排名
  {
    if(STU[i].score==STU[i-1].score)
      STU[i].final_rank=STU[i-1].final_rank;  //和前一个同学名次相同
    else
      STU[i].final_rank=i+1;          //否则排名为i+1
  }
  printf("%d\n",I);
  for(int i=0 ; i<I ; ++i)
    printf("%s %d %d %d\n",STU[i].ID,STU[i].final_rank,STU[i].location_number,STU[i].local_rank);
  return 0;
}
时间: 2024-08-03 01:04:11

PAT:1025. PAT Ranking (25) 编辑错误的相关文章

PAT 1025 PAT Ranking

#include <cstdio> #include <cstdlib> #include <vector> #include <cstring> #include <queue> #include <algorithm> using namespace std; class Man { public: char id[14]; int location; int score; int local_rank; }; class Ran

PAT 1025. 反转链表 (25)

给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转.例如:给定L为1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4:如果K为4,则输出应该为4→3→2→1→5→6,即最后不到K个元素不反转. 输入格式: 每个输入包含1个测试用例.每个测试用例第1行给出第1个结点的地址.结点总个数正整数N(<= 105).以及正整数K(<=N),即要求反转的子链结点的个数.结点的地址是5位非负整数,NULL地址用-1表示. 接下来有N行,每行格式为: Address Data Ne

1025 PAT Ranking (25 分)

1025 PAT Ranking (25 分) 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

1025 PAT Ranking (25分)

1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; struct stu{ int location_number; char

1025. PAT Ranking

1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneous

pat1025. PAT Ranking (25)

1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneous

1025 PAT Ranking[排序][一般]

1025 PAT Ranking (25)(25 分) 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 immediat

PAT 1075. PAT Judge (25)

题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1075 此题主要考察细节的处理,和对于题目要求的正确理解,另外就是相同的总分相同的排名的处理一定要熟练,还有就是编译没有通过为零分,没有提交显示为"-": #include <cstdio> #include <vector> #include <algorithm> using namespace std; const int NUM=10001

PAT 1025反转链表

1025反转链表 (25分) 给定一个常数 K 以及一个单链表 L,请编写程序将 L 中每 K 个结点反转.例如:给定 L 为 1→2→3→4→5→6,K 为 3,则输出应该为 3→2→1→6→5→4:如果 K 为 4,则输出应该为 4→3→2→1→5→6,即最后不到 K 个元素不反转. 输入格式: 每个输入包含 1 个测试用例.每个测试用例第 1 行给出第 1 个结点的地址.结点总个数正整数 N (≤105).以及正整数 K (≤N),即要求反转的子链结点的个数.结点的地址是 5 位非负整数,