PAT乙级1085-----PAT单位排行 (25分)

1085 PAT单位排行 (25分)

输入样例:

10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypu

输出样例:

5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2

思路:(struct school*)save[26][26][26]      (struct school*)inf[100005]
1.学校的末3位字符(转为小写)作为save的三个下标(不足3位默认一个数字),然后将每次输入存入save中,或者加入新的,或者加分数2.首次出现的school的指针存入inf中3.对inf快排

首次通过代码:

  1 #include<stdio.h>
  2 #include<string.h>
  3 #include<stdlib.h>
  4
  5 typedef struct school{
  6     char name[7];
  7     double score;
  8     int student_sum;
  9     struct school *next;
 10 }school,*s;
 11
 12 s initial_s(char name[]){
 13     s s1=(s)malloc(sizeof(school));
 14     strcpy(s1->name,name);
 15     s1->score=0;
 16     s1->student_sum=1;
 17     s1->next=NULL;
 18     return s1;
 19 }
 20
 21 void figure_score(s s1,int score,char x){
 22     if(x==‘A‘) s1->score+=(double)score;
 23     else if(x==‘B‘) s1->score+=(double)score/1.5;
 24     else if(x==‘T‘) s1->score+=(double)score*1.5;
 25 }
 26
 27 int cmp(const void* a , const void* b){
 28     s a1 = *(struct school**) a;    //强制类型转换
 29     s b1 = *(struct school**) b;
 30     int x=a1->score;int y=b1->score;
 31     if(x>y) return -1;
 32     else if(x==y&&a1->student_sum<b1->student_sum) return -1;
 33     else if(x==y&&a1->student_sum==b1->student_sum)
 34           return strcmp(a1->name,b1->name);
 35
 36    // return 1;
 37 }
 38
 39
 40 int main(){
 41    int sum;
 42    scanf("%d",&sum);
 43    s save[26][26][26]={NULL};
 44    s inf[100005]={NULL};
 45    int num=0;
 46    for(int i=0;i<sum;i++){
 47    char id[7];int score;char name[7];
 48    scanf("%s %d %s",id,&score,name);
 49    int x,y,z,flag=1;
 50       for(int j=0;;j++){
 51           if(name[j]>=‘A‘&&name[j]<=‘Z‘) name[j]=name[j]-‘A‘+‘a‘;
 52           if(name[j]==‘\0‘) break;
 53       }
 54       int len=strlen(name)-1;
 55       x=name[len]-‘a‘;
 56       len--;
 57       if(len>=0&&name[len]>=‘a‘&&name[len]<=‘z‘) y=name[len]-‘a‘;
 58       else y=25;
 59       len--;
 60       if(len>=0&&name[len]>=‘a‘&&name[len]<=‘z‘) z=name[len]-‘a‘;
 61       else z=25;
 62       if(save[x][y][z]==NULL){
 63           s s1=initial_s(name);
 64           figure_score(s1,score,id[0]);
 65           inf[num++]=s1;
 66           save[x][y][z]=s1;
 67       }
 68       else {
 69           s s2=save[x][y][z];
 70           while(s2!=NULL){
 71               if(strcmp(s2->name,name)==0){
 72                   figure_score(s2,score,id[0]);
 73                   s2->student_sum++;
 74                   flag=0;
 75                   break;
 76               }
 77               s2=s2->next;
 78           }
 79           if(flag){
 80             s s1=initial_s(name);
 81             figure_score(s1,score,id[0]);
 82             inf[num++]=s1;
 83             s1->next=save[x][y][z];
 84             save[x][y][z]=s1;
 85           }
 86       }
 87 }
 88 qsort(inf,num,sizeof(struct school*),cmp);
 89 int num1=1;
 90 int record=(int)inf[0]->score;
 91 int j=0;
 92 printf("%d\n",num);
 93 for(int i=0;i<num;i++){
 94     if((int)inf[i]->score!=record) {
 95         num1+=j;
 96         j=0;
 97     }
 98     printf("%d %s %d %d\n",num1,inf[i]->name,(int)inf[i]->score,inf[i]->student_sum);
 99     record=inf[i]->score;j++;
100 }
101 return 0;
102 }


指针数组快排参考:
FROM:https://www.cnblogs.com/nipan/p/4119714.html

原文地址:https://www.cnblogs.com/a982961222/p/12401527.html

时间: 2024-10-11 00:44:16

PAT乙级1085-----PAT单位排行 (25分)的相关文章

PAT乙级:1057 数零壹 (20分)

PAT乙级:1057 数零壹 (20分) 题干 给定一串长度不超过 105 的字符串,本题要求你将其中所有英文字母的序号(字母 a-z 对应序号 1-26,不分大小写)相加,得到整数 N,然后再分析一下 N 的二进制表示中有多少 0.多少 1.例如给定字符串 PAT (Basic),其字母序号之和为:16+1+20+2+1+19+9+3=71,而 71 的二进制是 1000111,即有 3 个 0.4 个 1. 输入格式: 输入在一行中给出长度不超过 105.以回车结束的字符串. 输出格式: 在

PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symmetric sub-string is s PAT&TAP s, hence you must output 11. In

pat 1013 Battle Over Cities(25 分) (并查集)

1013 Battle Over Cities(25 分) It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any othe

pat 1149 Dangerous Goods Packaging(25 分)

1149 Dangerous Goods Packaging(25 分) When shipping goods with containers, we have to be careful not to pack some incompatible goods into the same container, or we might get ourselves in serious trouble. For example, oxidizing agent (氧化剂) must not be

PAT 甲级 1083 List Grades (25 分)

1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades are in a given interval. I

PAT 甲级 1013 Battle Over Cities (25 分)(图的遍历,统计强连通分量个数,bfs,一遍就ac啦)

1013 Battle Over Cities (25 分) It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any oth

PAT 甲级 1036 Boys vs Girls (25 分)(简单题)

1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students. Input Specification: Each input file contains one test case. Each case contai

[PTA] PAT(A) 1007 Maximum Subsequence Sum (25 分)

目录 Problem Description Input Output Sample Sample Input Sample Output Solution Analysis Code Problem portal: 1007 Maximum Subsequence Sum (25 分) Description Given a sequence of $K$ integers { $N_{1}?$, $N_{2}?$, $...$, $N_{K}$ }. A continuous subsequ

[PTA] PAT(A) 1012 The Best Rank (25 分)

目录 Problem Solution Analysis Code Problem portal: 1012 The Best Rank (25 分) Solution Analysis ?一名学生有三门科目,以及计算出的一个平均成绩,每一个成绩都会有一个排名,现在想要让你输出某一个同学最高的排名(四种成绩排名的最高),以及对应的科目 ?如果给定的同学的四种课程排名的名次信息已经存在,那么就很简单,在里面找到最小的名次,以及对应的科目输出即可. ?可以创建四个数组,数组的每个元素存储某一门科目的