加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 09:11:21 所属栏目:百科 来源:网络整理
导读:题意: 输入洗牌次数K(=20),输入54张牌每次洗入的位置(不是交换的位置),输出洗好的牌。 代码: #define HAVE_STRUCT_TIMESPEC #includebits/stdc++.h using namespace std; multisetintst; int a[57]; int card[57],b[57]; int main(){ ios::sync_with_

题意:

输入洗牌次数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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读