P1093换成多组输入就会WA一个点

P1093 [NOIP2007 普及组] 奖学金

wade1998 @ 2019-07-02 16:01:55

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
struct node
{
    int xh;
    int yw,sx,yy,sum;
}a[320];
struct rule
{
    bool operator()(const node & n1,const node & n2)
    {
        if(n1.sum==n2.sum)
        {
            if(n1.yw==n2.yw)
            {
                return n1.xh<n2.xh;
            }
            return n1.yw>n2.yw;
        }
        return n1.sum>n2.sum;
    }
};
int main()
{
    int n;
    cin>>n;

    memset(a,0,sizeof(a));
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].yw>>a[i].sx>>a[i].yy;
        getchar();
        a[i].xh=i;
        a[i].sum=a[i].yw+a[i].sx+a[i].yy;
    }
    sort(a+1,a+1+n,rule());
    for(int i=1;i<=5;i++)
    {
        cout<<a[i].xh<<" "<<a[i].sum<<endl;
    }
    return 0;
}

这样单组输入是没有问题,能AC的。但是如下

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
struct node
{
    int xh;
    int yw,sx,yy,sum;
}a[320];
struct rule
{
    bool operator()(const node & n1,const node & n2)
    {
        if(n1.sum==n2.sum)
        {
            if(n1.yw==n2.yw)
            {
                return n1.xh<n2.xh;
            }
            return n1.yw>n2.yw;
        }
        return n1.sum>n2.sum;
    }
};
int main()
{
    int n;
    while(cin>>n)
    {
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++)
        {
            cin>>a[i].yw>>a[i].sx>>a[i].yy;
            getchar();
            a[i].xh=i;
            a[i].sum=a[i].yw+a[i].sx+a[i].yy;
        }
        sort(a+1,a+1+n,rule());
        for(int i=1;i<=5;i++)
        {
            cout<<a[i].xh<<" "<<a[i].sum<<endl;
        }
    }
    return 0;
}

不知道为什么就会WA掉9-10测试点??


by flying_whale @ 2019-09-30 11:26:26

第九个的测试数据给错了,写着n为220,实际却又221个。。。。


|