PTA 德才论

这个题说实话真的真的是题意好难理解啊,做了一个晚上,真是醉了,实际上写出来发现也没有那么困难,最要紧的原因还是自己对题目的理解不够,很多东西没有看到,最后说一句砸过缸的人就是不一样,随口一句话就是个题。

#include
#include
#include
#include
using namespace std;
typedef struct node
{
    int id,de,cai;
};
node x[4][100010];
bool cmp(node a,node b)
{
    int x = a.de + a.cai;
    int y = b.de + b.cai;
    if(x == y)
    {
        if(a.de == b.de)
        {
            return a.id < b.id;
        }
        return a.de > b.de;
    }
    return x > y;
}
int main()
{
    int n,l,h,a[4] = {0};
    scanf("%d %d %d",&n,&l,&h);
    for(int i = 0;i < n; i++)
    {
        node tp;
        scanf("%d %d %d",&tp.id,&tp.de,&tp.cai);
        if(tp.de >= h && tp.cai >= h)
            x[0][a[0]++] = tp;
        else if(tp.de >= h && tp.cai >= l)
            x[1][a[1]++] = tp;
        else if(tp.de >= l && tp.cai >= l && tp.de >= tp.cai)
            x[2][a[2]++] = tp;
        else if(tp.de >= l && tp.cai >= l)
            x[3][a[3]++] = tp;
    }
    printf("%d\n",a[0]+a[1]+a[2]+a[3]);
    for(int i = 0;i < 4; i++)
    {
        sort(x[i],x[i]+a[i],cmp);
        for(int j = 0;j < a[i]; j++)
            printf("%08d %d %d\n",x[i][j].id,x[i][j].de,x[i][j].cai);
    }
}

 

你可能感兴趣的:(PTA练习)