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 (≤) 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 <vector>
#include <string>
using namespace std;
int main()
{
int K, N = ;
vector<string>cards(N + ), res(N + ), temp(N + );
vector<int>n(N + );
for (int i = ; i <= N; ++i)
{
string s;
if (i <= )
s = "S" + to_string(i);
else if (i <= )
s = "H" + to_string(i - );
else if (i <= )
s = "C" + to_string(i - );
else if (i <= )
s = "D" + to_string(i - );
else
s = "J" + to_string(i - );
cards[i] = s;
}
cin >> K;
for (int i = ; i <= N; ++i)
cin >> n[i];
res = cards;
for (int i = ; i < K; ++i)
{
temp = res;
for (int j = ; j <= N; ++j)
res[n[j]] = temp[j];
}
for (int i = ; i <= N; ++i)
cout << res[i] << (i == N ? "" : " ");
return ;
}

PAT甲级——A1042 Shuffling Machine的更多相关文章

  1. PAT 甲级 1042 Shuffling Machine

    https://pintia.cn/problem-sets/994805342720868352/problems/994805442671132672 Shuffling is a procedu ...

  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

    1042 Shuffling Machine Shuffling is a procedure used to randomize a deck of playing cards. Because s ...

  4. A1042. Shuffling Machine

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

  5. A1042 Shuffling Machine (20)

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

  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. PAT A1042 Shuffling Machine

    自己思路,没通过 #include <cstdio> #define N 54 int main() { #ifdef ONLINE_JUDGE #else freopen("1 ...

  9. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

随机推荐

  1. php 扫描url死链接 \033[31m ANSI Linux终端输出带颜色

    * 从Packagist上搜索需要的包 https://packagist.org/ * 通过composer下载依赖包 composer require guzzlehttp/guzzlecompo ...

  2. python语句结构(range函数)

    python语句结构(range函数) range()函数 如果你需要遍历数字序列,可以使用内置range()函数,它会生成序列 也可以通过range()函数指定序列的区间 也可以使用range()函 ...

  3. MFC注册热键

    注册热键. 当用户点击注册的快捷键时,做出相应的响应. 定义 ALT+M键为测量按钮响应函数: 头文件中定义: #define ID_HOTKEY1 10001 在初始化函数中加入注册热键函数: if ...

  4. iOS开发系列-网络状态监控

    概述 在网络应用中,需要对用户设别的网络状态进行实时监控,可以让用户了解自己的网络状态出现网络问题提示用户. 一般在网络状态不好的场景下需要做一些处理比如: WIFT/3G/4G网络:自动下载高清图. ...

  5. C++右值引用与转移语义

    std::forwad? C++11 中定义的 T&& 的推导规则为: 右值实参为右值引用,左值实参仍然为左值引用. 参考: 右值引用与转移语义

  6. scoreboarding

    Reference docs: https://en.wikipedia.org/wiki/Scoreboarding SSC_course_5_Scoreboard_ex.pdf 1, what i ...

  7. about how to determine a prime number

    (1) if divided by 2 or 3, then no; (2) we only have to go through prime factors; because a composite ...

  8. 「BZOJ2388」旅行规划

    传送门 分块+凸包 求出前缀和数组s 对于l~r加上k,相当于s[l]~s[r]加上一个首项为k,公差为k的等差数列.r~n加上k*(r-l+1). 分块之后对每一块维护两个标记,一个记录它加的等差数 ...

  9. SSM项目实现连接两个mysql数据库

    最近做项目需要用到另一个数据库的内容,多方查找终于实现了功能. 我们都知道,在SSM框架中,我们在applicationContext.xml配置文件中添加数据源就可以实现数据库增删改查,但是只能连接 ...

  10. 三次面试总结以及今后的todolist

    金三银四跳槽季,按耐不住蠢蠢欲动的跳槽心,投了好多家的前端招聘,目前面了三家,有把握的零家.古人吾日三省吾身,我没那么高的觉悟,三面省一下自身,太咸鱼了是的我就是这么觉得的. 第一家公司在景田,很远, ...