菩提本无树,明镜亦非台.本来无一物,何处惹尘埃

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

题意分析:设计一个洗牌程序,要求整理N(54)张牌(扑克),输入一个随机数组,要求将该数组下标的牌放到该下标对应的数字的位置上!即当A[0]=10时,将第0张牌放到第10张牌的位置上。注意下标问题,题目中的随机数组是[1-64],我们是从0开始的到63,。注意减一

#include<iostream>
#include <cstring>
using namespace std;int main(){int times;int stu[54];//seedsint res[54];//resultsint temp[54];scanf("%d",&times);for(int a=0;a<54;a++){ //初始化atemp[a]=a;}for(int i=0;i<54;i++){scanf("%d",&stu[i]);}while(times--){for(int j=0;j<54;j++){res[stu[j]-1]=temp[j];}for(int s=0;s<54;s++){temp[s]=res[s];}}int yushu,shang;for(int k=0;k<54;k++){shang=res[k]/13;yushu=res[k]%13;if(shang==4&&yushu==0){printf("J1");if(k!=53)    printf(" ");continue;}if(shang==4&&yushu==1){printf("J2");if(k!=53)    printf(" ");continue;}if(shang==0) printf("S");if(shang==1) printf("H");if(shang==2) printf("C");if(shang==3) printf("D");printf("%d",yushu+1);if(k!=53)    printf(" ");}return 0;
}

PAT-A-1042 Shuffling Machine相关推荐

  1. PAT甲级1042 Shuffling Machine:[C++题解]模拟、哈希表、洗牌机

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析:序列置换. 这里用到函数memcpy()用于数组复制,用法memcpy(dest, src, sizeof dest); 把src数组 ...

  2. PAT:1042. Shuffling Machine (20) AC

    #include<stdio.h> #include<stdlib.h> const int N=54; int main() { char mp[5]={'S','H','C ...

  3. PAT甲级 1042 Shuffling Machine 模拟洗牌 map的使用

    Solution: 题目要求:要去实现一个模拟洗牌的程序.具体要求如下: (1)初始的排序已经给出. (2)要求洗k次牌,并输出最终排序. (3)给出54个数字,如果第i个位置上的数字为j,就要把第i ...

  4. 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 ...

  5. 1042. Shuffling Machine (20)

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

  6. 1042. Shuffling Machine (20)-PAT甲级真题

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

  7. 【题意分析】1042 Shuffling Machine (20 分)

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Shuffling is a procedure used to randomize a deck of playing card ...

  8. 1042 Shuffling Machine(简单题,用副本记录每次洗牌结果)

    目录 题目 测试样例 输入样例 输出样例 提交结果截图 带详细注释的源代码 题目 题目链接: 1042 Shuffling Machinehttps://pintia.cn/problem-sets/ ...

  9. PAT甲级1042~1055

    前言:距离四级考试剩23天,PAT甲级考试剩24天 对PAT甲级练习题做总结 1042 Shuffling Machine (20 分) 题目大意: 重复给出排列方式,把放在下标 i i i的牌调换到 ...

  10. PAT日志 1042

    顽强的小白 1042 Shuffling Machine (20 分) Shuffling is a procedure used to randomize a deck of playing car ...

最新文章

  1. Linux终端下 dstat 监控工具
  2. java.util.concurrent包详细分析--转
  3. lgg7深度详细参数_深度学习平均场理论第七讲:Batch Normalization会导致梯度爆炸?...
  4. linux close 头文件,Linux open close read write lseek函数的使用
  5. Java基础之不一样的方法重载!
  6. 《linux核心应用命令速查》连载三:sa:报告、清理并维护进程统计文件
  7. c3p0 服务启动获取连接超时_一次c3p0连接池连接异常错误的排查
  8. php 发送网易企业邮箱
  9. 数据泄露事件频发,深扒企业数据库安全隐患(内附高效防护手段)
  10. 迅雷下不了php文件怎么打开方式,如何解决迅雷打不开php文件的问题
  11. 玩转NVIDIA Jetson AGX Xavier--- 中文用户手册
  12. C-V2X 与智能车路协同技术的深度融合
  13. [转] Android开发环境的搭建 Android虚拟机搭建 安卓开发环境搭建
  14. nodejs+vue旅游网站设计
  15. 支付渠道接入设计及实现
  16. GET/POST 和TCP/UDP 区别
  17. mybatis提示XXX字段没有getter方法
  18. srgan要训练多久_核心训练需要做多久?学会这些动作,5分钟完成核心训练
  19. 复指数与高斯函数乘积的傅里叶变换_测量波函数
  20. 一分钟轻松解决阿里云盘无法分享压缩包问题

热门文章

  1. 7.Apache Kylin 创建cube 第一阶段报错Create Intermediate Flat Hive 报错 MapredLocalTask
  2. 网站视频详情页-网站-实践-scrapy框架
  3. Android 开发中使用硬件加速
  4. 遗传算法详细介绍以及基于遗传算法和非线性规划函数的寻优算法—MATLAB实现
  5. 古诗词html,意境唯美的古诗词完整 让人美的心醉的诗词
  6. python进阶day15
  7. 微服务设计指导-通过一个生产事故的具体例子来看微服务
  8. 微服务 - IaaS/PaaS/SaaS/BaaS - B2C/B2B
  9. 能否利用陀螺仪和加速度计,计算位移?
  10. 分析一个图像格式文件(PNG与TGA)