怎么错了?求助啊

P1093 [NOIP2007 普及组] 奖学金

pzx1466145162 @ 2017-05-24 13:25:35

#include <bits/stdc++.h>
using namespace std;
int yuwen[500],shuxue[500],yingyu[500],xuehao[500];
int main(){
    int n;
    cin>>n;
    int tmp;
    for(int i=1;i<=n;i++){
        xuehao[i]=i;
        cin>>yuwen[i];
        cin>>shuxue[i];
        cin>>yingyu[i];
    }
    int zong[500];
    for(int i=1;i<=n;i++){
        zong[i]=yuwen[i]+shuxue[i]+yingyu[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(zong[i]<zong[j]){
            tmp=zong[i];zong[i]=zong[j];zong[j]=tmp;
            tmp=xuehao[i];xuehao[i]=xuehao[j];xuehao[j]=tmp;
            }
            if(zong[i]==zong[j]){
                if(xuehao[i]>xuehao[j]){
                    tmp=zong[i];zong[i]=zong[j];zong[j]=tmp;
                    tmp=xuehao[i];xuehao[i]=xuehao[j];xuehao[j]=tmp;
                }
            }
            else continue;
        }
    }
    for(int i=1;i<=5;i++){
        cout<<xuehao[i]<<' ';
        cout<<zong[i]<<endl;
    }
    return 0;
}

by pzx1466145162 @ 2017-05-24 13:27:29

非常奇怪****

总分相同,学号小的在前面,可有时又跑到后面去了;求神犇


by pzx1466145162 @ 2017-05-25 12:49:20

哦,看掉了条件****


by pzx1466145162 @ 2017-05-25 13:02:32

#include <bits/stdc++.h>
using namespace std;
int yuwen[500],shuxue[500],yingyu[500],xuehao[500];
int main(){
    int n;
    cin>>n;
    int tmp;
    for(int i=1;i<=n;i++){
        xuehao[i]=i;
        cin>>yuwen[i];
        cin>>shuxue[i];
        cin>>yingyu[i];
    }
    int zong[500];
    for(int i=1;i<=n;i++){
        zong[i]=yuwen[i]+shuxue[i]+yingyu[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(zong[i]<zong[j]){
            tmp=zong[i];zong[i]=zong[j];zong[j]=tmp;
            tmp=xuehao[i];xuehao[i]=xuehao[j];xuehao[j]=tmp;
            }
            if(zong[i]==zong[j]){
                if(yuwen[i]<yuwen[j])
                {
                    tmp=zong[i];zong[i]=zong[j];zong[j]=tmp;
                    tmp=xuehao[i];xuehao[i]=xuehao[j];xuehao[j]=tmp;
                }
                if(yuwen[i]==yuwen[j]){
                    if(xuehao[i]>xuehao[j]){
                    tmp=zong[i];zong[i]=zong[j];zong[j]=tmp;
                    tmp=xuehao[i];xuehao[i]=xuehao[j];xuehao[j]=tmp;
                    }
                }
            }
        }
    }
    for(int i=1;i<=5;i++){
        cout<<xuehao[i]<<' ';
        cout<<zong[i]<<endl;
    }
    return 0;
}

by pzx1466145162 @ 2017-05-25 13:03:16

还是不对 痛彻心扉###


by pzx1466145162 @ 2017-05-25 13:11:12

AC了,原来忘记排序语文数组了

谢谢


by a1825055081 @ 2017-05-26 18:33:57

...


by noble_ @ 2017-05-29 21:11:20

其实可以用stl,自己写一个compare


by 李昊喆 @ 2017-05-30 09:38:48

#include<iostream>         
#include<algorithm>
using namespace std;
int main()
{
    int n,k,a[10001],b[10001],c[10001],d[10001],e[10001];
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
        d[i]=a[i]+b[i]+c[i];
        e[i]=i;
    }
    for(int i=1;i<=n-1;i++)
    {
        bool pass=true;
        for(int j=1;j<=n-i;j++)
        {
            if(d[j]<d[j+1])
            {
                swap(d[j],d[j+1]);
                swap(a[j],a[j+1]);
                swap(e[j],e[j+1]);
                pass=false;
            }
            else if(d[j]==d[j+1])
            if(a[j]<a[j+1])
            {
                swap(d[j],d[j+1]);
                swap(a[j],a[j+1]);
                swap(e[j],e[j+1]);
                pass=false;
            }
        }
        if(pass==true) break;
    }
    for(int i=1;i<=5;i++)
    cout<<e[i]<<" "<<d[i]<<endl;
    return 0;
}
这题目确实很烦!

|