zoukankan      html  css  js  c++  java
  • 7-31 The World's Richest (25分)

     

     

     解题思路:结构体排序

    按题目要求排序,再按年龄段和最大输出数目输出

    #include <stdio.h>
    #include <string.h>
    typedef char Element[9];
    typedef struct {
        Element Name;
        int age,wealth;
    } Bilionaires;
    int cmp(const void *a,const void *b) {
        Bilionaires *c=(Bilionaires*)a;
        Bilionaires *d=(Bilionaires*)b;
        if(c->wealth==d->wealth) {
            if(c->age==d->age)
                return strcmp(c->Name,d->Name);
            return c->age-d->age;
        }
        return d->wealth-c->wealth;
    }
    int main() {
        int n,k,i;
        int cnt,x,y;
        scanf("%d%d",&n,&k);
        Bilionaires B[n];
        for(i=0; i<n; i++) {
            scanf("%s%d%d",B[i].Name,&B[i].age,&B[i].wealth);
        }
        qsort(B,n,sizeof(B[0]),cmp);
        for(i=0; i<k; i++) {
            scanf("%d%d%d",&cnt,&x,&y);
            printf("Case #%d:
    ",i+1);
            int count=0;
    
            int j;
            for(j=0;j<n;j++) {
                if(B[j].age>=x&&B[j].age<=y) {
                    printf("%s %d %d
    ",B[j].Name,B[j].age,B[j].wealth);
                    count++;
                }
                if(count==cnt)
                    break;
            }
            if(!count)
                printf("None
    ");
    
        }
        return 0;
    }

  • 相关阅读:
    三角函数图像平移后重合对称
    三角恒等式的证明
    三角函数给值求角
    三角方程的解法
    空间中线面位置关系的证明思路
    实时会议
    LATEX 公式总结
    三维重建的应用
    会议
    计算机图形学学习笔记
  • 原文地址:https://www.cnblogs.com/snzhong/p/12815334.html
Copyright © 2011-2022 走看看