Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
34783 李羽乔 【S】T1 C++ 通过 100 174 MS 8096 KB 1663 2024-11-14 15:35:19

Tests(10/10):


#include<bits/stdc++.h> using namespace std; const int N = 1e6+10; int n,a[N],b[N]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } if(n<=1e3){ stack<int> s; stack<int> s2; for(int i=1;i<=n;i++){ if(i&1){ s.push(a[i]); while(!s.empty()){ int x=s.top(); s.pop(); s2.push(x); } } else{ s2.push(a[i]); while(!s2.empty()){ int x=s2.top(); s2.pop(); s.push(x); } } } if(n&1){ int cnt=0; while(!s2.empty()){ int x=s2.top(); s2.pop(); b[++cnt]=x; } for(int i=cnt;i>=1;i--) cout<<b[i]<<" "; cout<<endl; } else{ int cnt=0; while(!s.empty()){ int x=s.top(); s.pop(); b[++cnt]=x; } for(int i=cnt;i>=1;i--) cout<<b[i]<<" "; } } else{ int l=1,r=n,cnt=0,now=n; while(cnt<n){ b[l]=a[now]; now--; if(cnt==n-1) break; b[r]=a[now]; now--; cnt=cnt+2; l++; r--; } for(int i=1;i<=n;i++){ cout<<b[i]<<" "; } } return 0; }


测评信息: