解题思路:
注意事项:
参考代码:
#include <bits/stdc++.h>
using namespace std;
typedef struct student
{
int num,c_score,m_score,e_score,sum;
};
void cin_s(student *s,int n)
{
for(int i=0;i<n;i++)
{
cin>>s[i].c_score>>s[i].m_score>>s[i].e_score;
s[i].num=i+1;
s[i].sum=s[i].c_score+s[i].m_score+s[i].e_score;
}
return;
}
void sort_s(student *s,int n)
{
int i,j,m,low,high;
student temp;
for(i=1;i<n;i++)
{
low=0;
high=i-1;
while(low<=high)
{
m=(low+high)/2;
if(s[m].sum>s[i].sum)
low=m+1;
else if(s[m].sum==s[i].sum)
{
if(s[m].c_score>s[i].c_score)
low=m+1;
else if(s[m].c_score==s[i].c_score)
{
if(s[m].num>s[i].num)
high=m-1;
else
low=m+1;
}
else
high=m-1;
}
else
high=m-1;
}
temp=s[i];
for(j=i;j>high+1;j--)
s[j]=s[j-1];
s[high+1]=temp;
}
return;
}
void print_s(student *s,int n)
{
int i=0;
while(true)
{
cout<<s[i].num<<" "<<s[i].sum<<endl;
i++;
if(i==n||i==5)
break;
}
return;
}
int main()
{
int n;
cin>>n;
student *s=new student[n];
cin_s(s,n);
sort_s(s,n);
print_s(s,n);
return 0;
}
//祝大家高考顺利
0.0分
2 人评分
C语言程序设计教程(第三版)课后习题9.3 (Java代码)浏览:1025 |
printf基础练习2 (C语言代码)浏览:955 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:563 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:582 |
母牛的故事 (C语言代码)浏览:739 |
P1000 (C语言代码)浏览:911 |
1025题解浏览:796 |
简单的a+b (C语言代码)浏览:444 |
1134题解(求分析)浏览:795 |
【计算球体积】 (C语言代码)浏览:1619 |