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<bits/stdc++.h>
using namespace std;
vector<string> v;
void Init()
{
char s[5] = {'S', 'H', 'C', 'D', 'J'};
string tmp = "";
v.push_back(" ");
for(int i=0;i<4;i++)
{
for(int j=1;j<=13;j++)
{
tmp = s[i] + to_string(j);
v.push_back(tmp);
}
}
v.push_back("J1");
v.push_back("J2");
}
int main()
{
int n;
cin >> n;
Init(); vector<string> tmp(v);
int t;
int order[54];
for(int i=0;i<54;i++)
{
cin >> order[i];
} while(n--)
{
for(int i=0;i<54;i++)
{
tmp[order[i]] = v[i+1];
}
v.clear();
v.assign(tmp.begin(), tmp.end());
}
for(int i=1;i<v.size()-1;i++)
cout << v[i] << " ";
cout << v[v.size()-1];
return 0;
}
引用

https://pintia.cn/problem-sets/994805342720868352/problems/994805442671132672

PTA(Advanced Level)1042.Shuffling Machine的更多相关文章

  1. PAT (Advanced Level) 1042. Shuffling Machine (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

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

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

  3. PAT 1042. Shuffling Machine (20)

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

  4. PAT 1042 Shuffling Machine[难]

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

  5. 1042 Shuffling Machine (20 分)

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

  6. pat 1042 Shuffling Machine(20 分)

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

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

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

  8. PAT 1042 Shuffling Machine (20 分)

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

  9. PAT甲级——1042 Shuffling Machine

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

随机推荐

  1. How to Fix "Linux Failure to Download extra data files for ttf-mscorefonts-installer" error

    How to Fix "Linux Failure to Download extra data files for ttf-mscorefonts-installer" erro ...

  2. js--BOM对象(2)

    一.window对象是整个bom的核心 二.window对象的属性: history:(有关客户访问过的url信息) 方法: back() 加载 history 对象列表中的前一个URL forwar ...

  3. HNOI2012矿场搭建

    做完Mining Your Own Business后觉得这个题没什么意思了,数据范围小的连边数不清空都能A. 题解直接看这篇吧.做题的经历也挺……对吧. #include<iostream&g ...

  4. [心得]暑假DAY1 | 7-7考试总结

    呼.. 正式开始暑假集训. 今天一上午还在搞7-7的考试改题 然而,该来该去,TLE48过不去了 不知道哪的问题,loj上1w3ms(卡常都没能救得了) 至于T1和T3,简单总结一下算了 排序 感觉很 ...

  5. ping包的checksum校验和

    PING包发送里面有一个比较关键的就是checksum即校验和 checksum本来就是ICMP包内的数据 怎么又从ICMP包开始计算?后来看了一下文档,就是就算ICMP的时候checksum本身 的 ...

  6. android data binding jetpack II 动态数据更新

    android data binding jetpack VIII BindingConversion android data binding jetpack VII @BindingAdapter ...

  7. log4net保留几天内的日志

    想实现保留7天(一周)内的日志,网上一堆下述代码 <appender name="RollingLogFileAppender" type="log4net.App ...

  8. stm8问题记录

    sprintf 错误 现象:打印不出来数字 需要包含#include<stdio.h>

  9. 什么叫DMZ区?DMZ区有什么作用?应该怎样构建DMZ

    您的公司有一堆电脑,但可以归为两大类:客户机.服务器.所谓客户机就是主动发起连接请求的机器,所谓服务器就是被动响应提供某些服务的机器.服务器又可以分仅供企业内网使用和为外网提供服务两种. 所以,如果把 ...

  10. java逆向工程-mybatis-generator

    题记:在快速开发的项目中有使用到,这样可以避免冗余工作 声明:参考于https://www.cnblogs.com/smileberry/p/4145872.html 环境:必须先安装maven环境, ...