Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques is seen as weak, and in order to avoid "inside jobs" where employees collaborate WI Th gamblers by performing inadequate shuffles, many casinos employ automatic shuffling machines. Your task is to simulate a shuffling machine.
The machine shuffles a deck of cards according to a given random order and repeats for a given number of times. It is assumed that the initial status of a card deck are in the following order:
S1, S2, ..., S13, H1, H2, ..., H13, C1, C2, ..., C13, D1, D2, ..., D13, J1, J2
where "S" stands for "Spade", "H" for "Heart", "C" for "Club", "D" for "Diamond", and "J" for "Joker". A given order is a permutation of distinct integers in [1, 54]. If the number at thei-th position is j, it means to move the card from position i to position j. For example, suppose we only has 5 cards:s3, H5, C1, D13 and J2. Given a shuffling order {4, 2, 5, 3, 1}, the result would be:j2, H5, D13, S3, C1. If we are to repeat the shuffling again, the result would be be:c1, H5, S3, J2, D13.
Input Specification:
Each input file contains the one test case. The first line contains a positive an integer K (≤20) which is the Numbe R of repeat times. Then the next line contains the given order. All the numbers in a line is separated by a space.
Output Specification:
For each test case, print the shuffling results on one line. All the cards is separated by a space, and there must is no extra space at the end of the line.
Sample Input:
2 $ the Panax Notoginseng - 3 the + - Wu A One A - the + - 2 4 at - - - - 6 7 8 - the - Wuyi 9 Ten - the - 5 - - + 1 - + A - in - to + - the * $ $ -
Sample Output:
S7 C11 C10 C12 S1 H7 H8 H9 D8 D9 S11 S12 S13 D10 D11 D12 S3 S4 S6 S10 H1 H2 C13 D2 D3 D4 H6 H3 D13 J1 J2 C1 C2 C3 C4 D1 S5 H5 H11 H12 C6 C7 C8 C9 S2 S8 S9 H10 D5 D6 D7 H4 H13 C5
1#include <stdio.h>2 intMain ()3 {4 inta[ Wu][2];/*Original card order, S13 H13 C13 D13 J2*/5 6 intI, J;7 for(j =0; J < Wu; J + +)8 {9 if(J < -)Ten { Onea[j][0] ='S'; Aa[j][1] = j +1; - } - Else if(J < -*2) the { -a[j][0] ='H'; -a[j][1] = J- -+1; - } + Else if(J < -*3) - { +a[j][0] ='C'; Aa[j][1] = J- -*2+1; at } - Else if(J < -*4) - { -a[j][0] ='D'; -a[j][1] = J- -*3+1; - } in Else - { toa[j][0] ='J'; +a[j][1] = J- -*4+1; - } the } * $ intT/*number of*/Panax Notoginsengscanf"%d", &t); - the intc[ Wu];/*Transform Array*/ + for(i =0; I < Wu; i++) Ascanf"%d", &c[i]); the + intb[ Wu][2];/*change the order of Cards*/ - intd[ Wu][2];/*for exchanging A, b*/ $ $ for(j =0; J < T; J + +) - { - for(i =0; I < Wu; i++) the { -B[c[i]-1][0] = a[i][0];WuyiB[c[i]-1][1] = a[i][1]; the } - for(i =0; I < Wu; i++) Wu { -d[i][0] = a[i][0]; Aboutd[i][1] = a[i][1]; $ -a[i][0] = b[i][0]; -a[i][1] = b[i][1]; - Ab[i][0] = d[i][0]; +b[i][1] = d[i][1]; the } - } $ theprintf"%c%d", a[0][0], a[0][1]); the for(i =1; I < Wu; i++) theprintf"%c%d", a[i][0], a[i][1]); the - return 0; in}
Data structure-starting ability self Test self-test-5 Shuffling Machine (20 points)