P601 结构体

 

输入10个国家的国名、面积、人口,要求按面积从大到小排序,若面积相等,人口多的优先

#include<cstdio>
#include<algorithm>
using namespace std;
struct CT{
    char name[10];
    int area;
    double pop;
    bool operator <(const CT& b)const{
        if(area==b.area)return pop>b.pop;
        return area>b.area;
    }
}a[20];
int main(){
    int i,j;
    for(i=0;i<10;i++)scanf("%s %d %lf",&a[i].name,&a[i].area,&a[i].pop);
    sort(a,a+10);
    puts("===================");
    for(i=0;i<10;i++)printf("%s %d %g\n",a[i].name,a[i].area,a[i].pop);
    return 0;
}

  

 

 

SAMPLE DATA

USA 936 3.05
JPN 37 1.28
CHN 960 13.8
GER 35 0.82
UK 24 0.61
KOR 10 0.51
AUS 774 0.21
IND 328 11.8
CAN 997 0.33
RUS 1707 1.42

posted @ 2016-05-01 09:35  codeisking  阅读(211)  评论(0)    收藏  举报