2 solutions

  • 4
    @ 2024-2-6 17:05:24
    #include<bits/stdc++.h>
    using namespace std;
    int n;
    struct photo{
    	string x;
    	double l;
    }a[45];
    bool cmd(double a,double b){
    	return a>b;
    }
    double m[45],f[45];
    int q=-1,w=-1;
    int main(){
    	cin>>n;
    	for(int i=0;i<n;i++){
    		cin>>a[i].x>>a[i].l;
    		if(a[i].x[0]=='m') m[++q]=a[i].l;
    		else f[++w]=a[i].l;
    	}
    	sort(m,m+q+1);
    	sort(f,f+w+1,cmd);
    	for(int i=0;i<=q;i++) cout<<fixed<<setprecision(2)<<m[i]<<' ';
    	for(int i=0;i<=w;i++) cout<<fixed<<setprecision(2)<<f[i]<<' ';
    	return 0;
    }
    

    修bug修了十分钟

    • -2
      @ 2023-11-17 19:18:21
      #include<iostream>
      #include<string>
      #include<algorithm>
      #include<iomanip>
      using namespace std;
      struct people{
      	string sex;
      	float high;
      };
      bool sort_function(people first,people second){
      	if(first.sex!=second.sex){
      		return first.sex=="male";
      	}
      	else{
      		if(first.sex=="male"){
      			return first.high<second.high;
      		}
      		else{
      			return first.high>second.high;
      		}
      	}
      }
      int main(){
      	int many;
      	cin
      	>>many;
      	people friends_and_Xiaoyun[many];
      	for(int loop_body=0;loop_body<many;loop_body++){
      		cin
      		>>friends_and_Xiaoyun[loop_body].sex
      		>>friends_and_Xiaoyun[loop_body].high;
      	}
      	sort(friends_and_Xiaoyun,friends_and_Xiaoyun+many,sort_function);
      	for(int loop_body=0;loop_body<many;loop_body++){
      		cout
      		<<setprecision(2)
      		<<fixed
      		<<friends_and_Xiaoyun[loop_body].high
      		<<" ";
      	}
      }
      
      • 1

      Information

      ID
      668
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      8
      Tags
      # Submissions
      12
      Accepted
      11
      Uploaded By