NYOJ--714--Card Trick

/*
    Name: NYOJ--714--Card Trick
    Author: shen_渊 
    Date: 19/04/17 19:35
    Description: 早上训练的第六届河南省程序设计大赛的题,看了数据只有13个,(没毛病,可以打表)
                想用链表做,竟然没用过链表
                看了别人的队列做的,才知道队列也可以
                比赛的时候竟然是手算打表做的,心塞o(╯□╰)o 
*/
#include<bits/stdc++.h> //万能头文件 
using namespace std;
int a[14];
int d[14];
int main(){
    int k;cin>>k;
    while(k--) {
        int n;cin>>n;
        queue<int> q;
        for(int i=0; i<n; ++i){
            a[i] = i;
            q.push(a[i]);
        }
        int ct = 1;
        for(int i=1; i<=n; ++i){
            int j = i;
            while(j--){
                q.push(q.front());
                q.pop();
            }
            int x = q.front();q.pop();
            d[x] = ct++;
        }
        for(int i=0; i<n-1; ++i)cout<<d[i]<<" ";
        cout<<d[n-1]<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/langyao/p/7251866.html