Advertisement
Ankit_132

B

Feb 17th, 2024
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int t;
  7.     cin>>t;
  8.    
  9.     while(t--){
  10.         int n;
  11.         cin>>n;
  12.  
  13.         set<int> st;
  14.         for(int i=1; i<=n; i++)
  15.             st.insert(i);
  16.  
  17.         for(int i=1; i<=n; i++)
  18.         {
  19.             if(i%2)
  20.             {
  21.                 cout<<*st.begin()<<" ";
  22.                 st.erase(st.begin());
  23.             }
  24.             else
  25.             {
  26.                 cout<<*st.rbegin()<<" ";
  27.                 st.erase(--st.end());
  28.             }
  29.         }
  30.  
  31.         cout<<"\n";
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement