0
已解决
题目描述 Description
酷町堂举办了一次文件操作模拟赛,共有4道题目,现在要按照4道题目的平均分从高到低排序。如果分数相同,保持在输入中的顺序输出。
要求:求平均分要定义成一个返回值为double类型的结构体函数。
输入描述 Input Description
第一行,一个整数n,表示人数
接下来n行,每行有准考证号、第一题分数、第二题分数、第三题分数、第四题分数,准考证号是一个5位的字符串,由字母和数字构成
输出描述 Output Description
n行,每行一个排序后的准考证号
样例输入 Sample Input
5 BM001 100 0 0 100 BM002 100 20 80 80 BM003 100 100 0 100 BM004 100 100 100 0 BM005 100 100 100 100
样例输出 Sample Output
BM005 BM003 BM004 BM002 BM001
数据范围及提示 Data Size & Hint
n<=10000
没思路
0
已采纳
函数:
struct stu{
字符串 name;
整型变量 s1,s2,s3,s4;
整型变量 pos;
整型变量 score;
}a[10010];
bool cmp(stu x,stu y){
如果(x.score!=y.score){
return x.score大于y.score;
}
return x.pos小于y.pos;
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
整型变量 n;
输入n;
for(从1到n){
输入a[i].name和a[i].s1和a[i].s2和a[i].s3和a[i].s4;
a[i].pos等于i;
a[i].score等于a[i].s1+a[i].s2+a[i].s3+a[i].s4;
}
sort(a+1,a+1+n,cmp);
for(从1到n){
输出a[i].name和换行;
}
//fclose(stdin);
//fclose(stdout);
return 0;
}
0
struct stu{
string name;
int ch,ch1,ch2,ch3;
int id;
double ping(){
return (ch+ch1+ch2+ch3)/4.0;
}
}a[10005];
bool cmp(stu x,stu y){
if(x.ping()!=y.ping()){
return x.ping()>y.ping();
}
return x.id<y.id;
}
结构体排序
0
0