全部评论 1

  • #include<bits/stdc++.h>
    using namespace std;
    struct person{
    string sex;
    float height;
    }a[50];
    bool cmp(person a,person b){
    if(a.sex!=b.sex){
    if(a.sex=="male"){
    return true;
    }else{
    return false;
    }
    }else{
    if(a.sex=="male"){
    return a.height < b.height;
    }else{
    return a.height > b.height;
    }
    }
    }
    int main(){
    int n;
    cin>>n;
    for(int i = 0;i<n;i++){
    cin>>a[i].sex>>a[i].height; //输入
    }

    sort(a,a+n,cmp); 
    for(int i = 0;i<n;i++){
    	printf("%.2lf ",a[i].height);
    }
    return 0;
    

    }

    2025-01-02 来自 江苏

    0
首页