题解 | #整数奇偶排序#

整数奇偶排序

https://www.nowcoder.com/practice/bbbbf26601b6402c9abfa88de5833163

#include <cstdio>
#include <algorithm>
using namespace std;

bool comp(int x ,int y){
    if(x%2==1 && y%2==0){
        return true;
    }
    else if(x%2==1 && y%2==1 && x>y){
        return true;
    }
    else if(x%2==0 && y%2==0 &&x<y){
        return true;
    }
    else{
        return false;
    }
}

int main(){
    int arr[10];
    for (int i=0;i<10;i++){
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+10, comp);
    for (int i=0;i<10;i++){
        printf("%d ",arr[i]);
    }
    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务