Codeforces Gym - 339715I Playing With Arrays Gym Solution



Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n ; cin >> n ;
  11. deque<int>r(n) ;
  12. deque<int>a ;
  13. for ( int i = 0 ; i < n ; i++){
  14. r[i] = i + 1 ;
  15. }
  16. while(!r.empty()){
  17. a.push_front(r.back()) ;
  18. r.pop_back() ;
  19. a.push_front(a.back()) ;
  20. a.pop_back() ;
  21. }
  22. a.push_back(a.front()) ;
  23. a.pop_front() ;
  24. for ( int i = 0 ; i < a.size() ; i++){
  25. cout << a[i] ;
  26. if( i != a.size() - 1 ) cout <<" ";
  27. }
  28. cout << endl ;
  29. }
  30. return 0 ;
  31. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.