文章

81

粉丝

2

获赞

468

访问

8.5k

头像
排序 题解:
P1010 兰州大学/贵州大学机试
发布于2026年3月15日 14:56
阅读数 89

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

int main(){
    int n;
    cin >> n;

    int a[1005];
    for(int i=0;i<n;i++) cin >> a[i];

    sort(a,a+n);

    bool first = true;
    for(int i=0;i<n;i++){
        if(a[i]%2!=0){
            if(!first) cout << ' ';
            cout << a[i];
            first = false;
        }
    }

    for(int i=0;i<n;i++){
        if(a[i]%2==0){
            if(!first) cout << ' ';
            cout << a[i];
            first = false;
        }
    }

    cout << endl;
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发