pat00-自測5. Shuffling Machine (20)

00-自測5. Shuffling Machine (20)

時間限制
400 ms
內存限制
65536 kB
代碼長度限制
8000 B
判題程序
Standard
作者
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

提交代碼

?

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <string>
 4 #include <queue>
 5 #include <cmath>
 6 #include <iostream>
 7 using namespace std;
 8 char f[5]={'S','H','C','D','J'};
 9 int main(){
10     //freopen("D:\\INPUT.txt","r",stdin);
11     int time;
12     scanf("%d",&time);
13     int card1[55],card2[55],i,j;
14     for(i=0;i<=54;i++){
15         card1[i]=i;
16     }
17     int order[55];
18     for(i=1;i<=54;i++){
19         scanf("%d",&order[i]);
20     }
21     for(i=1;i<=time;i++){
22         for(j=1;j<=54;j++){
23             card2[order[j]]=card1[j];
24         }
25         for(j=1;j<=54;j++){
26             card1[j]=card2[j];
27         }
28     }
29     printf("%c%d",f[(card1[1]-1)/13],card1[1]%13==0?13:card1[1]%13);
30     for(i=2;i<=54;i++){
31         printf(" %c%d",f[(card1[i]-1)/13],card1[i]%13==0?13:card1[i]%13);
32     }
33     printf("\n");
34     return 0;
35 }

?

轉載于:https://www.cnblogs.com/Deribs4/p/4716788.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/375651.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/375651.shtml
英文地址,請注明出處:http://en.pswp.cn/news/375651.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

E488: Trailing characters:

情景&#xff1a; 對vim進行配置&#xff0c;配置完成后進行保存&#xff0c;配置完成后打開其他文件時報錯。原因&#xff1a; vim 配置文件中保存不合乎語法的語句&#xff0c;報錯時如下&#xff1a; #顯示行號 set number#字符導致的錯誤&#xff0c;改成"即可。 vi…

移動web開發總結

1、-webkit-tap-highlight-color:rgba(255,255,255,0)可以同時屏蔽ios和android下點擊元素時出現的陰影。 備注&#xff1a;transparent的屬性值在android下無效。2、-webkit-appearance:none可以同時屏蔽輸入框怪異的內陰影。3,/*去除android瀏覽器下a/input等元素獲得焦點時高…

人物角色群體攻擊判定二(叉乘來判斷敵人的位置)

建議閱讀: 判斷敵人在玩家的某一個區域: http://www.cnblogs.com/plateFace/p/4716799.html 我們可以根據玩家和敵人的坐標, 進行叉乘來獲取一個向量可以用它來判斷敵人的位置, 敵人是否在攻擊范圍內. 下面我簡單實現下對單體敵人是否攻擊做判定 這種方式有一種重大的BUG, 假設…

更改linux子系統軟件源為國內鏡像

cd /etc/apt/sudo cp sources.list sources.list.back20190831sudo vim sources.list執行vim替換命令 :%s/archive.ubuntu/mirrors.aliyun/g:%s/security.ubuntu/mirrors.aliyun/g執行sudo apt update即可。

[Z] Linux下進程的文件訪問權限

原文鏈接&#xff1a;http://blog.csdn.net/chosen0ne/article/details/10581883對進程校驗文件訪問權限包括兩個部分&#xff0c;一是確定進程的角色&#xff08;屬于哪個用戶或者組&#xff09;&#xff0c;二是確定對應的角色是否具有該操作的權限。 首先看第一部分。默認情…

HDU 5371 Manacher Hotaru's problem

求出一個連續子序列&#xff0c;這個子序列由三部分ABC構成&#xff0c;其中AB是回文串&#xff0c;A和C相同&#xff0c;也就是BC也是回文串。 求這樣一個最長的子序列。 Manacher算法是在所有兩個相鄰數字之間插入一個特殊的數字&#xff0c;比如-1&#xff0c; Manacher算法…

MySQL CURDATE() 函數

定義和用法 CURDATE() 函數返回當前的日期。 語法 CURDATE() 實例 例子 1 下面是 SELECT 語句&#xff1a; SELECT NOW(),CURDATE(),CURTIME() 結果類似&#xff1a; NOW()CURDATE()CURTIME()2008-12-29 16:25:462008-12-2916:25:46例子 2 下面的 SQL 創建帶有日期時間列 (Orde…

平庸技術流,用 WebApi +AngularJS 實現網絡爬蟲

最近園子里網絡爬蟲很火爆&#xff0c;從 PHP 到 Python&#xff0c;從 windows服務 到 winform 程序&#xff0c;各路大神各顯神通。小弟也獻下丑&#xff0c;從平庸流出發&#xff0c;簡述下 WebApi AngularJS 方式實現網絡爬蟲。 一、技術框架 1.1 前端&#xff1a; Angular…

linker `cc` not found

運行rustc hello_world.rs時出錯。原因&#xff1a; 我的 gcc 是安裝的指定版本 gcc-4.8&#xff0c;安裝指定版本 gcc 可參考我的另一篇博文&#xff0c;這里找不到 cc 的原因是在移除原來軟鏈的時候&#xff0c;cc 的軟鏈也移除了。重新建立軟鏈即可。 sudo ln -s gcc cc還有…

C# 通過服務啟動窗體(把窗體添加到服務里)實現用戶交互的windows服務[轉發]...

由于個人需要&#xff0c;想找一個鍵盤記錄的程序&#xff0c;從網上下載了很多&#xff0c;多數都是需要注冊的&#xff0c;另外也多被殺軟查殺。于是決定自己寫一個&#xff0c;如果作為一個windows應用程序&#xff0c;可以實現抓取鍵盤的記錄。想要實現隨系統啟動的話&…

error: default argument given for parameter 4

原因&#xff1a;定義函數的時候參數部分有默認值&#xff0c;如下&#xff1a; int classA::print(int a 0) {std::cout << a << std::endl; }分析&#xff1a;聲明函數時參數可以有默認值&#xff0c;定義時不能。

python2.7虛擬環境virtualenv安裝及使用

一 、虛擬環境virtualenv安裝 1. 安裝virtualenv 將Python的目錄添加到系統環境變量后&#xff0c;在命令行輸入&#xff1a; pip install virtualenv C:\Users\heroicai\Desktop>pip install virtualenv2. 建立虛擬環境 在桌面上建立建立一個虛擬環境myenv,輸入:virtualenv…

Io 異常: The Network Adapter could not establish the connection

Io 異常: The Network Adapter could not establish the connection 這個異常的出現一般與數據庫和你的PC的設置有關 這種異常的出現大致上有下面幾種&#xff1a; 1。IP錯誤。 在設置URL時錯誤&#xff0c;例如&#xff1a;jdbc:oracle:thin:192.168.0.36:1521:sharp 數據庫服…

git 刪除tag

git tag -d v1.0如果 tag 已經在遠程分支&#xff0c;還需執行一句git push origin :refs/tags/v1.0另&#xff1a;打 tag 的時候最好加上 description&#xff0c;防止出現未知的錯誤&#xff0c;如 Jenkins 集成的時候生成的包名不對等。

leetcode 的shell部分4道題整理

對shell的某些細節還不是十分熟悉&#xff0c;借鑒了好多別人的東西 1. Word Frequency此題很簡單&#xff0c;只要能排序就可以cat words.txt |tr -s " " "\n" sort | unique -c | sort -r | awk {print $2" "$1}2. Valid Phone Numbers cat …

Mysql操作集錦

mysql安裝成功后可以看到已經存在mysql、information_schema和test這個幾個數據庫&#xff0c;information_schema庫中有一個名為COLUMNS的表&#xff0c;這個表中記錄了數據庫中所有表的字段信息。知道這個表后&#xff0c;獲取任意表的字段就只需要一條select語句即可。 例如…

shadows a parameter

原因&#xff1a;函數內聲明變量與參數名相同。 如&#xff1a; void print(int hello) {int hello;std::cout << hello << std::endl; }解決辦法&#xff1a;改變參數參數名或者局部變量名

iOS 9之WatchKit for WatchOS 2

金田&#xff08;github示例源碼&#xff09; 自AppleWatch發行的同時就可以為AppWatch開發相應的應用程序&#xff0c;不過最初的版本&#xff0c;能開發的功能極為有限&#xff0c;所以也只是有少數的App廠商為Apple定制了App&#xff0c;所以迄今為止&#xff0c;Apple Stor…

創建響應式布局的10款優秀網格工具集錦

在這篇文章中&#xff0c;我們為您呈現了一組優秀的網格工具清單。如果我們錯過了任何沒有列出在這個清單上的東西&#xff0c;請分享給我們。如果網頁設計和開人員采用了正確的工具集&#xff0c;并基于一個靈活的網格架構&#xff0c;以及能夠把響應圖像應用到到設計之中&…

expected initializer before

原因&#xff1a;某個地方缺少分號 如&#xff1a; void print(int a) {int b ///wrong herestd::cout << a << std::endl; }解決&#xff1a;重點排查報錯行前幾行的變量聲明等。