Click Here to go back to the homepage.

Card Trick Solution:


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

int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int cases;
    cin >> cases;
    int n_cards;
    deque<int> deck;
    while(cases--){
        cin >> n_cards;
        deck.push_back(n_cards);
        while(--n_cards){
            deck.push_back(n_cards);
            for(int i = 0; i < n_cards; i++){
                deck.push_back(deck.front());
                deck.pop_front();
            }
        }
        while(!deck.empty()){
            cout << deck.back() << " ";
            deck.pop_back();
        }
        cout << endl;
    }

    return 0;
}