比赛 集训 评测结果 WWAWAAWAWW
题目名称 遵循指令之意 最终得分 40
用户昵称 pcx 运行时间 1.244 s
代码语言 C++ 内存使用 8.34 MiB
提交时间 2025-07-03 09:31:26
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int a[N],o[N],e[N],res[N];
int main(){
    freopen("sort.in","r",stdin);
    freopen("sort.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); 
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    int ol=0,el=0;
    for (int i=1;i<=n;++i) {
        if (i%2==1) {
            o[ol++]=a[i];
        }else{
            e[el++]=a[i];
        }
    }
    sort(o,o+ol);
    sort(e,e+el);
    ol=0,el=0;
    for(int i=1;i<=n;++i) {
        if (i%2==1) {
            res[i]=o[ol++];
        }else{
            res[i]=e[el++];
        }
    }
    for(int i=1;i<=n;i++) cout<<res[i]<<' ';
    return 0;
}