PAT乙级1085-----PAT单位排行 (25分)
Posted a982961222
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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]==‘