冒泡无解RE

P1093 [NOIP2007 普及组] 奖学金

lijiaqi @ 2018-11-14 21:40:11

RT

dalao求解,为啥这个冒泡不RE?

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=10000;
int stu[maxn],chi[maxn],math[maxn],eng[maxn],all[maxn];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>chi[i]>>math[i]>>eng[i];
        all[i]=chi[i]+math[i]+eng[i];
        stu[i]=i;
    }
    for(int i=1;i<=n-1;i++)
    {
        for(int j=1;j<=n-i;j++){
            if(all[j]<all[j+1]){
                swap(all[j],all[j+1]);
                swap(chi[j],chi[j+1]);
                swap(stu[j],stu[j+1]);
            }
            if(all[j]==all[j+1]&&chi[j]<chi[j+1]){
                swap(stu[j],stu[j+1]);
                swap(chi[j],chi[j+1]);
                swap(all[j],all[j+1]);
            }
            if(all[j]==all[j+1]&&chi[j]==chi[j+1]&&stu[j]>stu[j+1]){
                swap(stu[j],stu[j+1]);
                swap(chi[j],chi[j+1]);
                swap(all[j],all[j+1]);
            }
        }
    }
    for(int i=1;i<=5;i++)
        cout<<stu[i]<<" "<<all[i]<<endl;
    return 0;
}

然鹅我的冒泡却RE

#include<bits/stdc++.h>
using namespace std;
int xuhao[350],yu[350],shu[350],wai[350],zong[350];
int main()
{
    freopen("aa.in","r",stdin);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>yu[i]>>shu[i]>>wai[i];
        zong[i]=yu[i]+shu[i]+wai[i];
        xuhao[i]=i;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<i;j++)
        {
            if(zong[j]<zong[i])
            {
                int t=zong[j];
                zong[j]=zong[i];
                zong[i]=t;
                int r=xuhao[j];
                xuhao[j]=xuhao[i];
                xuhao[i]=r;
            }
            else if(zong[i]==zong[j]&&yu[j]<yu[i])
            {
                int t=zong[j];
                zong[j]=zong[i];
                zong[i]=t;
                int r=xuhao[j];
                xuhao[j]=xuhao[i];
                xuhao[i]=r;
            }
            else if(zong[i]==zong[j]&&yu[i]==yu[j]&&xuhao[j]<xuhao[i])
            {
                int t=zong[j];
                zong[j]=zong[i];
                zong[i]=t;
                int r=xuhao[j];
                xuhao[j]=xuhao[i];
                xuhao[i]=r;
            }
        }
    }
    for(int i=1;i<=5;i++)
    cout<<xuhao[i]<<" "<<zong[i]<<endl;
    return 0;
}

by lijiaqi @ 2018-11-14 21:40:52

freopen请省略


by dinghongyu @ 2018-11-14 21:47:30

因为第二个不是冒泡鸭


|