|20挑战4|CityGDP

    科技2024-10-25  10

    #include <iostream> #include <cstdio> #include <algorithm> using namespace std; struct City{ string name; double sum; double third_proportion; }city[1010]; bool cmp1(City a,City b){ return a.sum>b.sum; } bool cmp2(City a,City b){ return a.third_proportion>b.third_proportion; } int main() { int n; cin>>n; for(int i=1;i<=n;i++){ string city_name; cin>>city_name; city[i].name=city_name; double sum=0.0,third_proportion=0.0; for(int j=1;j<=3;j++){ double tmp; cin>>tmp; sum+=tmp; if(j==3){ third_proportion=tmp*1.0/sum; cout<<i<<" : "<<sum<<" "<<third_proportion<<endl; } } city[i].sum=sum; city[i].third_proportion=third_proportion; } sort(city,city+n,cmp1); cout<<city[0].name; sort(city,city+n,cmp2); cout<<" "<<city[0].name; return 0; }
    Processed: 0.023, SQL: 8