Codeforces Gym - 339715I Playing With Arrays Gym Solution
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n ; cin >> n ;
- deque<int>r(n) ;
- deque<int>a ;
- for ( int i = 0 ; i < n ; i++){
- r[i] = i + 1 ;
- }
- while(!r.empty()){
- a.push_front(r.back()) ;
- r.pop_back() ;
- a.push_front(a.back()) ;
- a.pop_back() ;
- }
- a.push_back(a.front()) ;
- a.pop_front() ;
- for ( int i = 0 ; i < a.size() ; i++){
- cout << a[i] ;
- if( i != a.size() - 1 ) cout <<" ";
- }
- cout << endl ;
- }
- return 0 ;
- }
No comments