PAT 1042. Shuffling Machine (20)
1042. Shuffling Machine (20)
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 <cstdio>
using namespace std;
const int N=54;
char mp[5]={'S','H','C','D','J'};
int s[N+1],e[N+1],n[N+1];
int main() {
int k;
scanf("%d",&k);
for(int i=1;i<=N;++i) s[i]=i;
for(int i=1;i<=N;++i) scanf("%d",&n[i]);
for(int num=0;num<k;++num) {
for(int i=1;i<=N;++i) e[n[i]]=s[i];
for(int i=1;i<=N;++i) s[i]=e[i];
}
for(int i=1;i<=N;++i) {
if(i!=1) printf(" ");
s[i]--;
printf("%c%d",mp[s[i]/13],s[i]%13+1);
}
return 0;
}
PAT 1042. Shuffling Machine (20)的更多相关文章
- PAT 1042 Shuffling Machine (20 分)
1042 Shuffling Machine (20 分) Shuffling is a procedure used to randomize a deck of playing cards. ...
- PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...
- PAT 甲级 1042 Shuffling Machine (20 分)(简单题)
1042 Shuffling Machine (20 分) Shuffling is a procedure used to randomize a deck of playing cards. ...
- PAT 1042 Shuffling Machine[难]
1042 Shuffling Machine (20)(20 分) Shuffling is a procedure used to randomize a deck of playing cards ...
- pat 1042 Shuffling Machine(20 分)
1042 Shuffling Machine(20 分) Shuffling is a procedure used to randomize a deck of playing cards. Bec ...
- 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 ...
- PAT(A) 1042. Shuffling Machine (20)
Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techn ...
- 1042. Shuffling Machine (20) - sstream实现数字转字符串
题目例如以下: Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffli ...
- 1042. Shuffling Machine (20)
Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techn ...
随机推荐
- Mybatis Generator生成Mybatis Dao接口层*Mapper.xml以及对应实体类
[前言] 使用Mybatis-Generator自动生成Dao.Model.Mapping相关文件,Mybatis-Generator的作用就是充当了一个代码生成器的角色,使用代码生成器不仅可以简化我 ...
- grunt-contrib-connect自动刷新html页面
grunt-contrib-connect可以在我们开发的时候自动刷新页面,省去了手动刷新的时间. 下面说一下如何配置grunt-contrib-connect 1.下载插件包 npm install ...
- Linux驱动模型解析bus之platform bus
这是内核启动之后要调用的驱动模型的开始代码: drivers/base/init.c/** * driver_init - initialize driver model. * * Call the ...
- Problem F
Problem Description "Yakexi, this is the best age!" Dong MW works hard and get high pay, h ...
- Brave Game(裸的巴什博弈)
Brave Game Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- js中的事件缓存机制
异步任务指的是,不进入主线程.而进入"任务队列"(task queue)的任务,只有"任务队列"通知主线程,某个异步任务可以执行了,该任务才会进入主线程执行. ...
- SSH框架整合--applicationContext.xml文件配置实例
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- 取得 iframe 容器的 URL
检测所在窗口是否为最外层的窗口,若不是则跳脱包含它的框架 if( window !== window.top ) { window.top.location = location; } top ...
- iOS 极光推送的集成以及一些集成后的狗血
1.首先进入极光文档下载激光推送的SDk---传送门http://docs.jiguang.cn/jpush/client/iOS/ios_sdk/ 将解压后的lib子文件夹(包含JPUSHSer ...
- Jenkins TFS配置
1. 在Jenkins中安装TFS插件 2. 在Build Server上安装tfs客户端程序,用来访问代码服务器获取代码, 这一部是由TFS Anywhere完成的 下载TFS Anywhere h ...