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
#include<iostream>
#include<string>
using namespace std;
int main(){
string a[],b[];
char temp[];
int c[],times;
cin>>times;
for(int i=;i<;i++){
cin>>c[i];
}
for(int i=;i<;i++){
if(i<=){
sprintf(temp,"%d",i);
string s(temp);
a[i]="S"+s;
}else if(i<=+){
sprintf(temp,"%d",i-);
string s(temp);
a[i]="H"+s;
}else if(i<=++){
sprintf(temp,"%d",i--);
string s(temp);
a[i]="C"+s;
}else if(i<=+++){
sprintf(temp,"%d",i---);
string s(temp);
a[i]="D"+s;
}
}
a[]="J1";
a[]="J2";
for(int j=;j<=times;j++){
for(int i=;i<=;i++){
b[c[i]]=a[i];
}
for(int i=;i<=;i++){
a[i]=b[i];
}
}
for(int i=;i<=;i++){
if(i==){
cout<<a[i];
}else{
cout<<a[i]<<" ";
} }
return ;
}

数据结构练习 00-自测5. Shuffling Machine (20)的更多相关文章

  1. pat00-自测5. Shuffling Machine (20)

    00-自测5. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Sh ...

  2. A1042 Shuffling Machine (20)

    1042 Shuffling Machine (20)(20 分) Shuffling is a procedure used to randomize a deck of playing cards ...

  3. PAT 1042. Shuffling Machine (20)

    1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shu ...

  4. PAT 甲级 1042 Shuffling Machine (20 分)(简单题)

    1042 Shuffling Machine (20 分)   Shuffling is a procedure used to randomize a deck of playing cards. ...

  5. PAT 1042 Shuffling Machine (20 分)

    1042 Shuffling Machine (20 分)   Shuffling is a procedure used to randomize a deck of playing cards. ...

  6. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

  7. PAT自测-5 Shuffling Machine

    原题连接https://pta.patest.cn/pta/test/17/exam/4/question/264 Shuffling is a procedure used to randomize ...

  8. 自测-5 Shuffling Machine

    Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techn ...

  9. 00-自测5. Shuffling Machine

    Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techn ...

随机推荐

  1. C语言之void类型及void指针 分类: C/C++ 2015-07-13 11:24 8人阅读 评论(0) 收藏

    原文网址:http://www.cnblogs.com/pengyingh/articles/2407267.html 1.概述 许多初学者对C/C 语言中的void及void指针类型不甚理解,因此在 ...

  2. Windows下Redis的安装使用[转]

    redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...

  3. careercup-链表 2.5

    2.5 给定两个用链表表示的整数,每个结点包含一个数位.这些数位是反向存放的,也就是个位排在链表首部.编写函数对这两个整数求和,并用链表形式返回结果. 示例: 输入: (7->1->6)+ ...

  4. pcap的pcap_dump()保存的文件格式

    (2009-09-01 20:36:49) 转载▼ 标签: 杂谈 分类: 专业 首先是tcpdump文件格式 当你在Windows或者Linux环境下用tcpdump命令抓取数据包时,你将得到如下格式 ...

  5. python学习笔记--Django入门四 管理站点--二

    接上一节  python学习笔记--Django入门四 管理站点 设置字段可选 编辑Book模块在email字段上加上blank=True,指定email字段为可选,代码如下: class Autho ...

  6. Eclipse将项目部署tomcat的webapps目录

      Eclipse将项目部署tomcat的webapps目录 >>>>>>>>>>>>>>>>>& ...

  7. SAMBA用户访问指定的目录

    指定某个用户访问一个特定的共享文件夹sfx 用户可以访问abc目录 别的用户不可以访问abc目录 先创建一个用户命令useradd sfx 创建一个smbpasswd用户 在创建这个用户时要先创建一个 ...

  8. Js的History对象

    History回顾 window.history表示window对象的历史记录 window.history的简单回顾 历史记录中前进/后退,移动到指定历史记录点 window.history.bac ...

  9. 为什么要设置Java环境变量(详解)

    关于java环境变量配置讲解: 1. PATH环境变量.作用是指定命令搜索路径,在shell下面执行命令时,它会到PATH变量所指定的路径中查找看是否能找到相应的命令程序.我们需要把 jdk安装目录下 ...

  10. PHP获得header头进行分析

    学web的人都知道,要深刻的理解就一定要对HTTP协议有深刻的理解,这样你才能理解整个运行的流程,有些功能你才能理解应该 如何去实现,比如:仿盗链啊,定义IP后切换页面语种的版本啊,等等, 这里就来对 ...