3 条题解

  • 3
    @ 2024-7-15 17:39:43
    #include<iostream>
    #include<algorithm>
    using namespace std;
    
    double man[41];
    double woman[41];
    int main(){
    	int n;
    	cin>>n;
    	string x;
    	double y;
    	int m=0,w=0;
    	for(int i=0;i<n;i++){
    		cin>>x>>y;
    		if(x=="male"){
    			man[m]=y;
    			m++;
    		}
    		if(x=="female"){
    			woman[w]=y;
    			w++;
    		}
    	}
    	sort(man,man+m);
    	sort(woman,woman+w);
    	w=w-1;
    	for(int i=0;i<m;i++){
    		printf("%.2lf",man[i]);
    		cout<<" ";
    	}
    	for(int j=w;j>=0;j--){
    		printf("%.2lf",woman[j]);
    		cout<<" ";
    	}
        return 0;
    }
    

    非常简单的sort

    • -2
      @ 2024-7-15 17:40:50
      [ ]()[]()
      
      
      ```none
      #include<iostream>
      #include<algorithm>
      using namespace std;
      
      double man[41];
      double woman[41];
      int main(){
      	int n;
      	cin>>n;
      	string x;
      	double y;
      	int m=0,w=0;
      	for(int i=0;i<n;i++){
      		cin>>x>>y;
      		if(x=="male"){
      			man[m]=y;
      			m++;
      		}
      		if(x=="female"){
      			woman[w]=y;
      			w++;
      		}
      	}
      	sort(man,man+m);
      	sort(woman,woman+w);
      	w=w-1;
      	for(int i=0;i<m;i++){
      		printf("%.2lf",man[i]);
      		cout<<" ";
      	}
      	for(int j=w;j>=0;j--){
      		printf("%.2lf",woman[j]);
      		cout<<" ";
      	}
      }
      

      Copy

      
      
      • @ 2024-7-15 17:42:46

        菜就多练,

      • @ 2024-7-15 17:44:19

        不要你以为你没有头像就拿别人的头像来嘲讽别人。dxx👎

      • @ 2024-7-15 17:46:38

        还有,你朝我题解还发我下面,什么意思???😕

      • @ 2024-7-15 17:50:04

        @就是!

      • @ 2024-7-15 17:50:44

        我cnm cnm cnm

    • -3
      @ 2024-7-15 17:39:45
      using namespace std;
      bool cmp(int x,int y){
      return x<y;
      }
      int main(){
      	int n,p=0,l=0;
      	float x,a[101],b[101];
      	string m;
      	cin>>n;
      	for (int i=1;i<=n;i++){
      		cin>>m>>x;
      		if (m=="male"){
      			a[++p]=x;
      		}else b[++l]=x;
      	}
      	sort(a+1,a+p+1);
      	sort(b+1,b+l+1);
      	for (int i=1;i<=p;i++){
      		printf("%.2f ",a[i]);
      	}
      	for (int i=l;i>=1;i--){
      		printf("%.2f ",b[i]);
      	}
              return 0;
      }
      
      • 1

      信息

      ID
      254
      时间
      1000ms
      内存
      256MiB
      难度
      7
      标签
      递交数
      176
      已通过
      35
      上传者