top1编程
← 返回题目
题解

合影效果

1 条题解

  • 0
    @ 2026-7-28 22:45:05
    #include<bits/stdc++.h>
    using namespace std;
    bool cmp(double a,double b){
    	if(a>b){
    		return true;
    	}else{
    		return false;
    	}
    }
    int main(){
    	int n;
    	double a[50],b[50];
    	int x=0,y=0;
    	double h;
    	string s;
    	cin>>n;
    	for(int i=1;i<=n;i++){
    		cin>>s>>h;
    		if(s=="male"){
    			a[++x]=h;
    		}else{
    			b[++y]=h;
    		}
    	}
    	sort(a+1,a+x+1);
    	sort(b+1,b+y+1,cmp);
    	for(int i=1;i<=x;i++){
    		cout<<fixed<<setprecision(2)<<a[i]<<" ";
    	}
    	for(int i=1;i<=y;i++){
    		cout<<fixed<<setprecision(2)<<b[i]<<" ";
    	}
    }
    
    • 1