2 solutions

  • 2
    @ 2024-11-30 14:28:40
    #include<bits/stdc++.h>//a+(a&-a)
    using namespace std;
    int a[10]={};
    int e[10]={},o[10]={};
    int q=-1,w=-1;
    bool c1(int x,int y){
    	return x<y;
    }
    bool c2(int x,int y){
    	return x>y;
    }
    int main(){
    	for(int i=0;i<10;i++){
    		cin>>a[i];
    		if(a[i]%2==0) e[++q]=a[i];
    		else o[++w]=a[i];
    	}
    	sort(o,o+w+1,c2);
    	sort(e,e+q+1,c1);
    	for(int i=0;i<=w;i++) cout<<o[i]<<' ';
    	for(int i=0;i<=q;i++) cout<<e[i]<<' ';
    	cout<<"\n";
    	return 0;
    }
    
    • -6
      @ 2024-1-27 8:27:06

      题解,非常简单的一题

      #include<iostream>
      #include<algorithm>
      using namespace std;
      bool px(int a,int b){
      	if(a%2==b%2){
      		if(a%2==1){
      			if(a<b)return 1;
      			return 0;
      		}
      		if(a>b)return 1;
      		return 0;
      	}
      	if(a%2==1)return 0;
      	return 1;
      }
      int main(){
      	int a[10];
      	for(int i=0;i<10;i++)cin>>a[i];
      	sort(a,a+10,px);
      	for(int i=9;i>=0;i--)cout<<a[i]<<" ";
      }
      
      • 1

      Information

      ID
      667
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      6
      Tags
      # Submissions
      18
      Accepted
      11
      Uploaded By