数据结构-起步能力自测题 自测-5 Shuffling Machine(20 分)

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with 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 54 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 is 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 the i-th position is j, it means to move the card from position i to position j. For example, suppose we only have 5 cards: S3, H5, C1, D13 and J2. Given a shuffling order {4, 2, 5, 3, 1}, the result will be: J2, H5, D13, S3, C1. If we are to repeat the shuffling again, the result will be: C1, H5, S3, J2, D13.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive integer K (≤20) which is the number of repeat times. Then the next line contains the given order. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print the shuffling results in one line. All the cards are separated by a space, and there must be no extra space at the end of the line.

Sample Input:

2
36 52 37 38 3 39 40 53 54 41 11 12 13 42 43 44 2 4 23 24 25 26 27 6 7 8 48 49 50 51 9 10 14 15 16 5 17 18 19 1 20 21 22 28 29 30 31 32 33 34 35 45 46 47


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 int main()
 3 {
 4     int a[54][2];    /*原始牌次序,S13 H13 C13 D13 J2*/
 5
 6     int i, j;
 7     for (j = 0; j < 54; j++)
 8     {
 9         if (j < 13)
10         {
11             a[j][0] = ‘S‘;
12             a[j][1] = j + 1;
13         }
14         else if (j < 13 * 2)
15         {
16             a[j][0] = ‘H‘;
17             a[j][1] = j - 13 + 1;
18         }
19         else if (j < 13 * 3)
20         {
21             a[j][0] = ‘C‘;
22             a[j][1] = j - 13 * 2 + 1;
23         }
24         else if (j < 13 * 4)
25         {
26             a[j][0] = ‘D‘;
27             a[j][1] = j - 13 * 3 + 1;
28         }
29         else
30         {
31             a[j][0] = ‘J‘;
32             a[j][1] = j - 13 * 4 + 1;
33         }
34     }
35
36     int t;    /*次数*/
37     scanf("%d", &t);
38
39     int c[54];    /*变换数组*/
40     for (i = 0; i < 54; i++)
41         scanf("%d", &c[i]);
42
43     int b[54][2];    /*变换后牌次序*/
44     int d[54][2];    /*用于交换a,b*/
45
46     for (j = 0; j < t; j++)
47     {
48         for (i = 0; i < 54; i++)
49         {
50             b[c[i] - 1][0] = a[i][0];
51             b[c[i] - 1][1] = a[i][1];
52         }
53         for (i = 0; i < 54; i++)
54         {
55             d[i][0] = a[i][0];
56             d[i][1] = a[i][1];
57
58             a[i][0] = b[i][0];
59             a[i][1] = b[i][1];
60
61             b[i][0] = d[i][0];
62             b[i][1] = d[i][1];
63         }
64     }
65
66     printf("%c%d", a[0][0], a[0][1]);
67     for (i = 1; i < 54; i++)
68         printf(" %c%d", a[i][0], a[i][1]);
69
70     return 0;
71 }

原文地址:https://www.cnblogs.com/Emerl/p/8964723.html

时间: 2024-10-11 03:01:01

数据结构-起步能力自测题 自测-5 Shuffling Machine(20 分)的相关文章

pat00-自测5. Shuffling Machine (20)

00-自测5. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "insid

00-自测5. Shuffling Machine (20)

00-自测5. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "insid

数据结构练习 00-自测5. Shuffling Machine (20)

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, many cas

数据结构与算法题目集(中文)——5-13 统计工龄 (20分)——桶排序

给定公司NN名员工的工龄,要求按工龄增序输出每个工龄段有多少员工. 输入格式: 输入首先给出正整数NN(\le 10^5≤10?5??),即员工总人数:随后给出NN个整数,即每个员工的工龄,范围在[0, 50]. 输出格式: 按工龄的递增顺序输出每个工龄的员工个数,格式为:"工龄:人数".每项占一行.如果人数为0则不输出该项. 输入样例: 8 10 2 0 5 7 2 5 2 输出样例: 0:1 2:3 5:2 7:1 10:1  时间限制:400ms 内存限制:64MB 代码长度限制

PAT甲题题解-1042. Shuffling Machine (20)-模拟

博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789205.html特别不喜欢那些随便转载别人的原创文章又不给出链接的所以不准偷偷复制博主的博客噢~ 给出洗牌次数,以及洗牌的序列规则第i个数shuffles[i]表示要将第i张牌移到第shuffles[i]个 很简单,就是shuffle_seq[shuffles[i]]=start_seq[i]; #include <iostream> #include

pat00-自测3. 数组元素循环右移问题 (20)

00-自测3. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0A1……AN-1)变换为(AN-M …… AN-1 A0 A1……AN-M-1)(最后M个数循环移至最前面的M个位置).如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法? 输入格式:每个输入包含一个测试

自测-5 Shuffling Machine

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, many cas

PAT自测-5 Shuffling Machine

原题连接https://pta.patest.cn/pta/test/17/exam/4/question/264 Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate

Hadoop自测题及参考答案(持续更新中--2015.6.14)

单选题 1.与其他几项不同的是 A. Mesos B. Mongodb C. Corona D. Borg E. YARN 注:其他几项都是资源统一管理系统或者资源统一调度系统,而 Mongodb一种非关系型数据库. 2.[java基础] 以下不属于线程安全的数据结构是 A. HashMap B. HashTable C. CopyOnWriteArrayList D. ConcurrentHashMap 3.hadoop2.x采用什么技术构建源代码 A. ant B. ivy C. maven