PAT A1042 Shuffling Machine

news/2024/10/23 9:24:02/

1042 Shuffling Machine

分数 20

作者 CHEN, Yue

单位 浙江大学

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 <algorithm>
#include <string>using namespace std;const int N = 100;
string s[N], temp[N];
int idx;
int ver[N];void Init()
{string flag[] = {"S", "H", "C", "D"};for(int i=0; i<4; ++i){for(int j=1; j<14; ++j){string sub = to_string(j);string temp = flag[i] + sub;s[++idx] = temp;}}s[++idx] = "J1", s[++idx] = "J2";
}int main()
{Init();int t;cin >> t;for(int i=1; i<55; ++i)cin >> ver[i];while(t--){for(int i=1; i<55; ++i)temp[ver[i]] = s[i];for(int i=1; i<55; ++i) s[i] = temp[i];}for(int i=1; i<55; ++i){if(i != 1)  cout << ' ';cout << s[i];}return 0;
}


http://www.ppmy.cn/news/63099.html

相关文章

golang的os包用法简介

文章目录 简述os 包中的常用函数HostnameEnvironGetenvSetenvExitGetuidGetgidGetpidGetwdMkdirMkdirAllRemove os/exec 执行外部命令LookPath os/user 获取当前用户信息Current os/signal 信号处理NotifyStop 简述 Go语言的 os 包中提供了操作系统函数的接口&#xff0c;是一个…

数据导向下制造业的生产效率、交易效率提升办法

在智能制造和工业4.0成为趋势的今天&#xff0c;大部分制造业企业&#xff0c;均已在企业内部通过实施PLM系统&#xff08;Product Lifecycle Management&#xff0c;产品生命周期管理系统&#xff09;&#xff0c;实现了对组织内产品研发过程和产品研发数据的管理&#xff0c;…

初级算法-动态规划

主要记录算法和数据结构学习笔记&#xff0c;新的一年更上一层楼&#xff01; 初级算法-动态规划 一、斐波那契数二、爬楼梯三、使用最小花费爬楼梯四、不同路径五、不同路径二六、整数拆分七、不同的二叉搜索树八、0-1背包九、分割等和子集十、最后一块石头的重量十一、目标和…

Word控件Spire.Doc 【打印】教程(2):保打印word文档不显示打印处理对话框

Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下&#xff0c;轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具&#xff0c;专注于创建、编辑、转…

webp格式转换成jpg,webp转jpg方法步骤

webp格式转换成jpg&#xff0c;webp转jpg方法步骤。办公室工作集科学性、规范性于一体&#xff0c;仅凭过去的一些经验和习惯&#xff0c;很难提升工作的质量和水平。因此&#xff0c;作为办公室工作人员来说&#xff0c;必须要以科学的理念&#xff0c;运用现代办公管理软件来…

车载测试-can报文解析规则实例

报文解析 报文组成 一般报文主要有以下几个参数&#xff08;比较全的情况下&#xff09; 例 解析报文时主要用到的是帧ID和帧数据 帧ID 接收到的帧ID是十六进制的形式&#xff0c;由29位标识符转换的&#xff0c;目前大多数的通信协议中都直接给出了相应的帧ID&#xff0c…

Nacos-01-Nacos基本介绍

背景 ​ 服务发现是⼀个古老的话题&#xff0c;当应用开始脱离单机运行和访问时&#xff0c;服务发现就诞生了。目前的网络架构是每个主机都有⼀个独立的 IP 地址&#xff0c;那么服务发现基本上都是通过某种方式获取到服务所部署的 IP 地址。DNS 协议是最早将⼀个网络名称翻译…

283.移动零

链接 https://leetcode.cn/problems/move-zeroes/ 题目 给定一个数组 nums&#xff0c;编写一个函数将所有 0 移动到数组的末尾&#xff0c;同时保持非零元素的相对顺序。 请注意 &#xff0c;必须在不复制数组的情况下原地对数组进行操作。 提示: 1 < nums.length < 10…