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

题目大意:看了许久,没明白,参考了下别人的才明白。原先的序列是a {1,2,3,4,5},需要根据输入的b {4,2,5,3,1}来洗牌,具体洗牌过程是,b[i]=a[i],这样得到的结果是序列{5,2,4,1,3}即等于{J2,H5,D13,S3,C1}

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int max=54;
int a[max],b[max],c[max];
int n,i,j;
scanf("%d",&n);
for(i=0;i<max;i++){
a[i]=i;
scanf("%d",b+i);
}
while(n--){
for(i=0;i<max;i++){
c[i]=a[i];
}
for(j=0;j<max;j++){
a[b[j]-1]=c[j];
}
}
for(j=0;j<max;j++){
int k = a[j]/13;
if(k==0){
printf("S%d",a[j]%13+1);
}else if(k==1){
printf("H%d",a[j]%13+1);
}else if(k==2){
printf("C%d",a[j]%13+1);
}else if(k==3){
printf("D%d",a[j]%13+1);
}else if(k==4){
printf("J%d",a[j]%13+1);
}
if(j+1==max){
printf("\n");
}else{
printf(" ");
}
}
return 0;
}

  

1042. Shuffling Machine (20)的更多相关文章

  1. PAT 1042. Shuffling Machine (20)

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

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

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

  3. PAT 1042 Shuffling Machine (20 分)

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

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

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

  5. 1042. Shuffling Machine (20) - sstream实现数字转字符串

    题目例如以下: Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffli ...

  6. PAT Advanced 1042 Shuffling Machine (20 分)(知识点:利用sstream进行转换int和string)

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

  7. PAT(A) 1042. Shuffling Machine (20)

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

  8. 1042 Shuffling Machine (20分)(水)

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

  9. 【PAT甲级】1042 Shuffling Machine (20 分)

    题意: 输入洗牌次数K(<=20),输入54张牌每次洗入的位置(不是交换的位置),输出洗好的牌. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC ...

随机推荐

  1. centos安装桌面,下面的几个包缺一不可

    yum groupinstall “X window system” yum groupinstall “Desktop” yum groupinstall “Chinese Support” 不然的 ...

  2. 第二十天 模块 sys os os下path settings random shuit

    一.sys模块 1.sys.argv 命令行参数List,第一个元素是程序本身路径 2.sys.exit(n) 退出程序,正常退出时exit(0) 3.sys.version 获取Pythonn解释程 ...

  3. Matplotlib学习---用matplotlib画阶梯图(step plot)

    这里利用Nathan Yau所著的<鲜活的数据:数据可视化指南>一书中的数据,学习画图. 数据地址:http://datasets.flowingdata.com/us-postage.c ...

  4. 【XSY2524】唯一神 状压DP 矩阵快速幂 FFT

    题目大意 给你一个网格,每个格子有概率是\(1\)或是\(0\).告诉你每个点是\(0\)的概率,求\(1\)的连通块个数\(\bmod d=0\)的概率. 最开始所有格子的概率相等.有\(q\)次修 ...

  5. MT【266】求$a$的范围

    已知 $a$ 为常数,函数$f(x)=\dfrac{x}{\sqrt{a-x^2}-\sqrt{1-x^2}}$ 的最小值为$-\dfrac{2}{3}$,则 $a$ 的取值范围_____ 解: 考虑 ...

  6. 【CF997E】Good Subsegments (线段树+单调栈)

    Description 原题链接 给你一个长度为\(n\)的排列\(~P\),定义一段子区间是好的,当且仅当这个子区间内的值构成了连续的一段.例如对于排列\(\{1,3,2 \}\),\([1, 1] ...

  7. Angular、React.js 和Node.js到底选谁?

    为了工作,程序员选择正确的框架和库来构建应用程序是至关重要的,这也就是为什么Angular和React之间有着太多的争议.Node.js的出现,让这场战争变得更加复杂,虽然有选择权通常是一件很棒的事情 ...

  8. centos7添加并挂载新硬盘

    环境目标: 配置一台centos7,主硬盘40G装系统:副硬盘200G作为数据盘(格式:XFS)挂载到根目录:/data/ 说明:XFS是高性能文件系统,SGI为他们的 IRIX平台而设计: 自从20 ...

  9. PHP函数memory_get_usage获取PHP内存清耗量

    (PHP 4 >= 4.3.2, PHP 5, PHP 7) memory_get_usage — 返回分配给 PHP 的内存量 说明 int memory_get_usage ([ bool ...

  10. 万物互联之~RPC专栏

    3.RPC引入 上篇回顾:万物互联之~深入篇 Code:https://github.com/lotapp/BaseCode/tree/master/python/6.net/6.rpc/ 其他专栏最 ...