文章

16

粉丝

44

获赞

2

访问

4.8k

头像
整数奇偶排序 题解:C++
P1248 北京大学机试题
发布于2024年3月10日 20:36
阅读数 246

#include <bits/stdc++.h>
using namespace std;
bool cmp(int a,int b){
    if(a%2==1&&b%2==1)
        return a>b;
    else if(a%2==0&&b%2==0)
        return a<b;
    else
        return (a%2)>(b%2);
}
int main(){
    int a[11];
    while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6]>>a[7]>>a[8]>>a[9]){
        sort(a,a+10,cmp);
        for (int i = 0; i < 10; ++i)
            cout<<a[i]<<" ";
        cout<<endl;
    }

    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发