自测-5 Shuffling Machine (20 分)
发布日期:2022-02-10 08:11:12 浏览次数:15 分类:技术文章

本文共 2138 字,大约阅读时间需要 7 分钟。

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

该题目实际上为PAT甲级1042题。

题目大意:
模拟洗牌机器,将每个位置上的牌放到输入数字位置的那个位置上去。
思路:
构造两个数组,一个数组来储存进行运算后的牌的位置,一个数组来储存原先每个牌的位置,(必须这么做!因为牌可能会洗很多次,这样才能实现)
可以构造char【5】={S,H,C,D,J},来储存花色。
一开始犯了个简单错误:
在这里插入图片描述
这样子是不能交换牌的值的。。
在一个就是得要两个数组来运算,一个数组要储存在洗了一次牌之后,所有牌得位置,方便多次洗牌的运算。
代码如下:
在这里插入图片描述

转载地址:https://blog.csdn.net/qq_45380840/article/details/101177019 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:解决virtualbox安装增强功能显示未能加载虚拟光盘问题
下一篇:自测-4 Have Fun with Numbers (20 分)

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月16日 09时58分04秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

Java多线程(案例+解析)JDK5.0新增的线程的创建方式 2019-04-26
OCJP考试习题(1z0-808)答案+解析 2019-04-26
Java全栈开发---Java ERP系统开发:商业ERP(十一)库存预警,JavaMail发送预警邮件 2019-04-26
Android快速入门 基础知识,系统架构(快速开发第一个安卓应用程序) 2019-04-26
Java实现QQ邮件发送(JavaMail)(Maven版) 2019-04-26
Java 实现定时任务(Quartz 框架)定时执行某个任务(Maven版) 2019-04-26
Java全栈开发---Java ERP系统开发:商业ERP(十二)数据的导入导出(Excel) 2019-04-26
Java 操作Excel表格(POI)(Maven),创建表格,画边框线,合并单元格,设置内容,设置行高和列宽,设置对齐方式和字体 2019-04-26
2021年Java何去何从,在人工智能,云计算,物联网,区域块链,大数据的背景下Java未来会怎样发展?(网友回答) 2019-04-26
Android快速入门 四大应用组件之一Activity(打电话和发短信)功能练习 2019-04-26
Java全栈开发---Java ERP系统开发:商业ERP(十三)CXF框架,物流BOS系统开发 2019-04-26
Java CXF框架(案例加解析)(快速入门)模拟服务端和客户端(客户端远程调用服务端功能) 2019-04-26
Java全栈开发---Java ERP系统开发:商业ERP(十四)ERP系统的权限分配 2019-04-26
Android快速入门-----用户界面(上)UI组件 2019-04-26
Mybatis快速入门(2)Dao封装-属性加载:抽取JDBC-别名的配置-映射器(mappers) 2019-04-26
Android快速入门-----数据存储(一)SharedPreferences存储,手机内部file存储,手机外部file存储:SD卡外部file存储 2019-04-26
Java当中ArrayList的indexOf()方法总结,String类型和其它类型的不同 2019-04-26
Java当中子类继承父类(总结)几种特殊情况 2019-04-26
Intellij IDEA 的快捷方式设置为Eclipse风格 2019-04-26
Java当中当接口的default修饰的方法,实现类调用该的方法的方式 2019-04-26