Codeforces 1462 A. Favorite Sequence

Codeforces 1462 A. Favorite Sequence
在这里插入图片描述
在这里插入图片描述
思路分析:
看着题怪长,其实就是类似与回文字符串,搞一个双指针就好了

AC代码:

#include <iostream>

using namespace std;

const int N = 310;

int a[N];

int main() {
    
    
    int t;
    cin >> t;
    while (t--) {
    
    
        int n;
        cin >> n;
        for(int i=0;i<n;i++)
            cin >> a[i];
        for(int i = 0,j = n-1;i<=j;i++,j--) {
    
    
            if( i != j)
                cout << a[i] << ' ' << a[j] << ' ';
            else
                cout << a[i];
        }
        cout << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_45654671/article/details/112727569
今日推荐