Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
48545 刘轻松 奖学金 C++ Accepted 1 MS 272 KB 1183 2023-06-09 23:30:37

Tests(10/10):


Code:

# include<iostream> using namespace std; //定义学生结构体 struct student{ int no; int yuwen; int shuxue; int yingyu; int total; }; //两个学生进行对比 bool cmp(student x,student y){ if(x.total<y.total){ return true; } else if(x.total==y.total){ if(x.yuwen<y.yuwen){ return true; } else if(x.yuwen==y.yuwen){ if(x.no>y.no){ return true; } } } return false; } int main(){ int n; cin>>n; student stu[301]; student temp; for(int i=0;i<n;i++){ stu[i].no=i+1; cin>>stu[i].yuwen>>stu[i].shuxue>>stu[i].yingyu; stu[i].total = stu[i].yuwen+stu[i].shuxue+stu[i].yingyu; } for(int i=0;i<n-1;i++){ for(int j = 0;j<n-i-1;j++){ if(cmp(stu[j],stu[j+1])){ temp = stu[j]; stu[j] = stu[j+1]; stu[j+1] = temp; } } } for(int i=0;i<5;i++){ cout<<stu[i].no<<" "<<stu[i].total<<endl; } return 0; }


Run Info: