2 10 8 dxy male 230 225 davidwang male 218 235 evensgn male 150 175 tpkuangmo female 34 21 guncuye male 5 15 faebdc male 245 250 lavender female 220 216 qmqmqm male 250 245 davidlee male 240 160 dxymeizi female 205 190 2 1 dxy male 300 300 dxymeizi female 0 0
The member list of Shandong team is as follows: faebdc qmqmqm davidwang dxy lavender dxymeizi davidlee evensgn The member list of Shandong team is as follows: dxymeizi Hint For the first testcase: the highest mark of Round1 if 250,so every one's mark times(300/250)=1.2, it's same to Round2. The Final of The Ultimate score is as followed faebdc 298.20 qmqmqm 295.80 davidwang 275.88 dxy 271.80 lavender 260.64 dxymeizi 233.40 davidlee 220.80 evensgn 201.00 tpkuangmo 29.88 guncuye 14.40 For the second testcase,There is a girl and the girl with the highest mark dxymeizi enter the team, dxy who with the highest mark,poorly,can not enter the team.
简单结构体的排序题。
代码如下:
#include <stdio.h> #include <algorithm> #include <string.h> using namespace std; struct people { char name[22]; char sex[10]; double round[3]; double grade; }per[101]; bool cmp1(people a,people b) { return a.grade>b.grade; } int main() { int u,n,m; //计算次数 总人数 目标人数 int dot; //有无女生参加选拔,0为无,1为有 double max[3]; //存放最大成绩 double mark[3]; //两次的基本分倍数 int girl; //是否输出了女孩?0为假 scanf ("%d",&u) ; while (u--) { scanf ("%d %d",&n,&m); memset (per,0,sizeof(per)); dot=0; girl=0; /*for (int i=0;i<n;i++) { scanf ("%s %s %lf %lf",&per[i].name,&per[i].sex,&per[i].round[1],&per[i].round[2]); } for (int i=max[1]=0;i<n;i++) { if (per[i].round[1]>max[1]) { max[1]=per[i].round[1]; } } for (int i=max[2]=0;i<n;i++) { if (per[i].round[2]>max[2]) { max[2]=per[i].round[2]; } }*/ scanf ("%s",per[0].name); scanf ("%s",per[0].sex); if (per[0].sex[0]=='f') dot=1; scanf ("%lf",&per[0].round[1]); max[1]=per[0].round[1]; scanf ("%lf",&per[0].round[2]); max[2]=per[0].round[2]; for (int i=1;i<n;i++) { scanf ("%s",per[i].name); scanf ("%s",per[i].sex); if (per[i].sex[0]=='f') dot=1; scanf ("%lf",&per[i].round[1]); if (per[i].round[1]>max[1]) { max[1]=per[i].round[1]; } scanf ("%lf",&per[i].round[2]); if (per[i].round[2]>max[2]) { max[2]=per[i].round[2]; } } if (!m) { printf ("The member list of Shandong team is as follows:\n"); continue; } printf ("The member list of Shandong team is as follows:\n"); mark[1]=300.0/max[1]; mark[2]=300.0/max[2]; for (int i=0;i<n;i++) { per[i].grade=per[i].round[1]*mark[1]*0.3+per[i].round[2]*mark[2]*0.7; } sort(per,per+n,cmp1); /*printf ("\n"); for (int i=0;i<n;i++) { printf ("%s %lf\n",per[i].name,per[i].grade); } printf ("max=%lf %lf\n",max[1],max[2]); printf ("max=%lf %lf\n",mark[1],mark[2]); printf ("\n"); */ //测试sort排序正误 if (!dot) { for (int i=0;i<m;i++) { printf ("%s\n",per[i].name); } } else { for (int i=0;i<m-1;i++) { printf ("%s\n",per[i].name); if (per[i].sex[0]=='f') girl=1; } if (girl) { printf ("%s\n",per[m-1].name); } else { for (int j=m-1;j<n;j++) { if (per[j].sex[0]=='f') { printf ("%s\n",per[j].name); break; } } } } } return 0; }