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

分析:简单模拟。使用start和end数组保存每一次变换的开始顺序和结束顺序(以1~54的编号存储),最后根据编号与扑克牌字母数字的对应关系输出end数组

#include <cstdio>
using namespace std;
int main() {int cnt;scanf("%d", &cnt);int start[55], end[55], scan[55];for(int i = 1; i < 55; i++) {scanf("%d", &scan[i]);end[i] = i;}for(int i = 0; i < cnt; i++) {for(int j = 1; j < 55; j++)start[j] = end[j];for(int k = 1; k < 55; k++)end[scan[k]] = start[k];}char c[6] = {"SHCDJ"};for(int i = 1; i < 55; i++) {end[i] = end[i] - 1;printf("%c%d", c[end[i]/13], end[i]%13+1);if(i != 54) printf(" ");}return 0;
}

1042. Shuffling Machine (20)-PAT甲级真题相关推荐

  1. 1120. Friend Numbers (20)-PAT甲级真题

    1120. Friend Numbers (20) Two integers are called "friend numbers" if they share the same ...

  2. 1081. Rational Sum (20)-PAT甲级真题

    Given N rational numbers in the form "numerator/denominator", you are supposed to calculat ...

  3. 1077. Kuchiguse (20)-PAT甲级真题

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  4. 1031. Hello World for U (20)-PAT甲级真题

    Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. ...

  5. 1042. 字符统计(20)-PAT乙级真题

    请编写程序,找出一段给定文字中出现最频繁的那个英文字母. 输入格式 输入在一行中给出一个长度不超过1000的字符串.字符串由ASCII码表中任意可见字符及空格组成,至少包含1个英文字母,以回车结束(回 ...

  6. 1061. Dating (20)-PAT甲级真题

    Sherlock Holmes received a note with some strange strings: "Let's date! 3485djDkxh4hhGE 2984akD ...

  7. 1108. Finding Average (20)-PAT甲级真题

    The basic task is simple: given N real numbers, you are supposed to calculate their average. But wha ...

  8. PAT甲级真题目录(按题型整理)(转自柳神)

    转载自:https://www.liuchuo.net/archives/2502?tdsourcetag=s_pcqq_aiomsg 最短路径 1003. Emergency (25)-PAT甲级真 ...

  9. 1042 Shuffling Machine (20 point(s)) - C语言 PAT 甲级

    1042 Shuffling Machine (20 point(s)) Shuffling is a procedure used to randomize a deck of playing ca ...

最新文章

  1. Tensorflow框架是如何支持分布式训练的?
  2. 配置phoenix连接hbase_Phoenix4.14不读取hbase配置文件-问答-阿里云开发者社区-阿里云...
  3. pywt.upcoef中take使用详解
  4. linux 安装x11 apt-get,Mac 安装apt-get
  5. java 全局变量 内存不回收_JAVA知识梳理:内存管理与垃圾回收机制
  6. Spring Security——异常信息本地化
  7. Character,String相关方法,Int,double互相转换
  8. 推荐系统系列教程之十六:深度和宽度兼具的融合模型
  9. DIV+CSS颜色边框背景等样式
  10. Vue三大核心之三(插槽)
  11. Scala深入浅出实战初级入门经典视频课程
  12. 20200714一维数组的经典例题(成绩的最高分,最低分;猜中数字游戏;数组的增添改查;)
  13. 工业相机 - - 线阵相机
  14. python画圆及其内接多边形_用Shapely求多边形的最大内接矩形
  15. ndows10cad安装不上,win10安装cad2014会显示连接不到网络
  16. rtl8188eu无线网卡驱动linux,rtl8188eu驱动下载-rtl8188eu无线网卡驱动程序v1.0 官方版 - 极光下载站...
  17. 远程协助计算机如何开启,远程协助怎么开
  18. 马云给公司年轻员工的一封信
  19. office 文档在线预览新姿势之永中云转换
  20. python进行JB正态性检验

热门文章

  1. synchronized同步机制
  2. FBReaderJ源码编译配置
  3. Android 中的Intent的某些用法
  4. Spring Boot 学习系列(01)—从0到1,只需两分钟
  5. 使用 Helm - 每天5分钟玩转 Docker 容器技术(163)
  6. FastDFS-单机版安装
  7. 【码云周刊第 3 期】来自国内开发者的实战项目,开源让通讯从未如此简单!...
  8. swiper的基础使用(九)
  9. MYSQL 主从复制读写分离实现
  10. Zabbix添加监控项及配置邮件报警