【PAT甲】A1042

原创 2018年04月17日 21:33:35
//乙级刷了前50题,现在开始刷甲级,争取在8-9月份把PAT甲级考出来
/*
*时间:2018年4月17日20:24:18-2018年4月17日21:02:30
*题目: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>
using namespace std;

int main()
{	
	int n;
	int order[54];
	string temp[54];
	string initOrder[54] = {"S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10", "S11", "S12","S13",
							"H1", "H2", "H3", "H4", "H5", "H6", "H7", "H8", "H9", "H10", "H11", "H12","H13",
							"C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10", "C11", "C12","C13",
							"D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "D10", "D11", "D12","D13",
							"J1", "J2"};
	cin>>n;
	for (int i=0; i<54; i++)
	{
		cin>>order[i];	
	}
	for (int i=0; i<n; i++)
	{
		for (int j=0; j<54; j++)
		{
			temp[order[j]-1] = initOrder[j];//temp为变换后的数组,表示temp的第order[j]-1个元素为initOrder[j]
		}
		for (int j=0; j<54; j++)//再把initOrder数组用temp赋值
			initOrder[j] = temp[j];
	}
	for(int i=0; i<54; i++)
	{
		if (i == 53) cout<<initOrder[53];
		else cout<<initOrder[i]<<" ";
	}
		
	return 0;
}



























More Effective C++ 条款28(中)

 条款28:灵巧(smart)指针(中) 测试灵巧指针是否为NULL目前为止我们讨论的函数能让我们建立、释放、拷贝、赋值、dereference灵巧指针。但是有一件我们做不到的事情是“发现灵巧指针为N...
  • zhc
  • zhc
  • 2001-12-12 09:42:00
  • 913

PAT A1042

1042. Shuffling Machine (20) Shuffling is a procedure used to randomize a deck of playing cards...
  • dancheng1
  • dancheng1
  • 2016-12-17 19:37:31
  • 173

pat a1042

#include #include #include #include using namespace std; char typeofcard[6]="SHCDJ"; int start[...
  • herbertlkyz
  • herbertlkyz
  • 2017-02-13 11:31:50
  • 368

【PAT】1042. 字符统计(20)

字符统计(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 请编写程序,找出一段给定文字...
  • artemisrj
  • artemisrj
  • 2016-03-01 20:58:25
  • 836

浙大PAT 1042题 1042. Shuffling Machine

#include #include int main(){ char map[55][5]={"Null","S1","S2","S3","S4","S5","S6","S7","S8","S...
  • Sup_Heaven
  • Sup_Heaven
  • 2014-02-10 08:05:30
  • 1080

PAT甲级1003

传送门 仔细分析一下,你就会发现这实际上是一道单源最短路径问题,不过有个小坑是路径可能不止一条,同时要注意这是一个无向图。我第一次弄成有向图了,可以用Dijksttra和DFS结合,可以破之。 #...
  • u013220338
  • u013220338
  • 2015-12-03 19:28:19
  • 1019

pat 甲1003. Emergency(最短路)

1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 ...
  • qq_27601815
  • qq_27601815
  • 2016-11-16 17:12:32
  • 168

PAT甲级1023

1023. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 St...
  • qq_22194315
  • qq_22194315
  • 2017-01-23 01:04:16
  • 191

PAT(甲级)1018

1018. Public Bike Management (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 ...
  • Leonardo1897
  • Leonardo1897
  • 2015-09-23 16:59:38
  • 236

PAT 1032. Sharing

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1032 题解: 给两个字符串的链表存储,如果两个字符有相同的后缀,其后缀会存放在相同内存块,问这两个...
  • ACM_Ted
  • ACM_Ted
  • 2014-03-01 00:10:36
  • 1303
收藏助手
不良信息举报
您举报文章:【PAT甲】A1042
举报原因:
原因补充:

(最多只允许输入30个字)