【PAT甲级】1042 Shuffling Machine (20 分)

题意:

输入洗牌次数K(<=20),输入54张牌每次洗入的位置(不是交换的位置),输出洗好的牌。

代码:

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
multiset<int>st;
int a[57];
int card[57],b[57];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
for(int i=1;i<=54;++i)
card[i]=i;
int k;
cin>>k;
for(int i=1;i<=54;++i)
cin>>a[i];
for(int i=1;i<=k;++i){
if(i&1)
for(int j=1;j<=54;++j)
b[a[j]]=card[j];
else
for(int j=1;j<=54;++j)
card[a[j]]=b[j];
}
int x=0;
for(int i=1;i<=54;++i){
if(k&1)
x=b[i];
else
x=card[i];
if(x<=13)
cout<<"S"<<x;
else if(x<=26)
cout<<"H"<<x-13;
else if(x<=39)
cout<<"C"<<x-26;
else if(x<=52)
cout<<"D"<<x-39;
else
cout<<"J"<<x-52;
if(i<54)
cout<<" ";
}
return 0;
}

原文地址:https://www.cnblogs.com/ldudxy/p/11588634.html

时间: 2024-10-05 08:28:40

【PAT甲级】1042 Shuffling Machine (20 分)的相关文章

PAT(A) 1042. Shuffling Machine (20)

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, D

1042 Shuffling Machine (20分)

1. 题目 2. 思路 常规题目 3. 注意点 无 4. 代码 #include<cstdio> #include<vector> #include<string> using namespace std; int n; int order[55]; vector<string> cards; void init_cares(){ cards.push_back(""); //占位 for(int i=1;i<=13;i++){ c

PAT:1042. Shuffling Machine (20) AC

#include<stdio.h> #include<stdlib.h> const int N=54; int main() { char mp[5]={'S','H','C','D','J'}; int n; scanf("%d",&n); int start[N],end[N],next[N]; for(int i=1 ; i<=N ; ++i) //初始化 start[i]=i; for(int i=1 ; i<=N ; ++i) /

PAT 1042. Shuffling Machine (20)

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

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 cas

1042. Shuffling Machine (20) - sstream实现数字转字符串

题目如下: 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, ma

PAT甲级——A1042 Shuffling Machine

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 cas

PAT 甲级 1015 Reversible Primes (20 分) (进制转换和素数判断(错因为忘了=))

1015 Reversible Primes (20 分) A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime. Now given

PAT 甲级 1041 Be Unique (20 分)(简单,一遍过)

1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1]. The first one who bets on a unique number wins. For example