求助!只过了第一个点!

P5740 【深基7.例9】最厉害的学生

___wa___ @ 2022-08-11 19:31:21

代码有点很长
#include<bits/stdc++.h>
using namespace std;
struct xuesheng
{
    string mingzi;
    int yuwen,shuxue,yingyu;
    int zongchengji;
    int id;
}xuesheng[1001];
int main()
{
    int a;
    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>xuesheng[i].mingzi;
        cin>>xuesheng[i].yuwen;
        cin>>xuesheng[i].shuxue;
        cin>>xuesheng[i].yingyu;
        xuesheng[i].id=i;
    }
    for(int i=0;i<a;i++)
    {
        xuesheng[i].zongchengji=xuesheng[i].yuwen+xuesheng[i].shuxue+xuesheng[i].yingyu;
    }
    for(int i=0;i<a;i++)
    {
        for(int ii=0;ii<a;ii++)
        {
            if(xuesheng[i].zongchengji<xuesheng[ii].zongchengji&&xuesheng[i].id<xuesheng[ii].id)
            {
                swap(xuesheng[i].zongchengji,xuesheng[ii].zongchengji);
                swap(xuesheng[i].mingzi,xuesheng[ii].mingzi);
                swap(xuesheng[i].id,xuesheng[ii].id);
                swap(xuesheng[i].yuwen,xuesheng[ii].yuwen);
                swap(xuesheng[i].shuxue,xuesheng[ii].shuxue);
                swap(xuesheng[i].yingyu,xuesheng[ii].yingyu);
            }
            else
            if(xuesheng[i].zongchengji==xuesheng[ii].zongchengji)
                if(xuesheng[i].id<xuesheng[ii].id)
                {
                    swap(xuesheng[i].zongchengji,xuesheng[ii].zongchengji);
                    swap(xuesheng[i].mingzi,xuesheng[ii].mingzi);
                    swap(xuesheng[i].id,xuesheng[ii].id);
                    swap(xuesheng[i].yuwen,xuesheng[ii].yuwen);
                    swap(xuesheng[i].shuxue,xuesheng[ii].shuxue);
                    swap(xuesheng[i].yingyu,xuesheng[ii].yingyu);
                }
        }
    }
    cout<<xuesheng[0].mingzi<<" "<<xuesheng[0].yuwen<<" "<<xuesheng[0].shuxue<<" "<<xuesheng[0].yingyu;
    return 0;
 }

样例过了

求dalao帮助!


by GuangyuHuashi @ 2022-08-12 18:08:16

能理解吗


by GuangyuHuashi @ 2022-08-12 18:10:07

for(int i=0;i<a-1;i++)
    for(int ii=i+1;ii<a;ii++)//只遍历后面的,就不论如何大的都会换到前面,后面更小的就无所谓了

by ___wa___ @ 2022-08-12 18:13:10

理解了谢谢dalao


by ___wa___ @ 2022-08-12 18:15:37

AC了


上一页 |