ZJANS

d562. 山寨版磁力蜈蚣

Medium Last Update: 2026/02/01
陣列

解法一

✅ 完整代碼

評分結果(參考) : AC (89ms, 320KB)

#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    while(cin >> n){
        vector<int> a(n);
        for(int& i : a) cin >> i;
        
        bool rev = false;
        int l=0, r=n;
        for(int i=0; i<n; i++){
            for(int j=l; j<r; j++){
                if(rev) cout << a[n-j-1] << " ";
                else cout << a[j] << " ";
            }
            if(rev) l++;
            else r--;
            rev = !rev;
            cout << "\n";
        }
        cout << "\n";
    }
    
    return 0;
}