2 solutions

  • 0
    @ 2026-9-19 16:22:49
    #include<bits/stdc++.h>
    using namespace std;
    struct Person {
    	string sex;
    	double height;
    };
    const int N=50;
    Person p[N];
    bool cmp(Person a,Person b)
    {
    	if(a.sex=="male"&&b.sex=="female") return 1; 
    	if(a.sex=="male"&&b.sex=="male"&&a.height<b.height) return 1;   
    	if(a.sex=="female"&&b.sex=="female"&&a.height>b.height) return 1;   
    	return 0;
    }
    int main()
    {
    	int n;
    	cin>>n;
    	for(int i=0;i<n;i++)
    	{
    		cin>>p[i].sex>>p[i].height;
    	}
    	sort(p,p+n,cmp);
    	for(int i=0;i<n;i++)
    	{
    		cout<<fixed<<setprecision(2)<<p[i].height<<" "; 
    	}
    	return 0;
    }

    Information

    ID
    947
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    1
    Tags
    (None)
    # Submissions
    58
    Accepted
    28
    Uploaded By