这个【PAT甲级】1042 Shuffling Machine的题目是关于什么长尾词的排序机器的?
- 内容介绍
- 文章标签
- 相关推荐
本文共计407个文字,预计阅读时间需要2分钟。
题意:输入商标次数K(K=20),输入54张牌每次洗入的位置(不是交换的位置),输出洗好的牌。
代码:pythondef shuffle_cards(K, positions): # 初始化牌堆 deck=list(range(1, 55)) # 洗牌过程 for _ in range(K): for pos in positions: deck.insert(pos, deck.pop(0)) return deck
输入示例K=20positions=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53]
输出结果result=shuffle_cards(K, positions)print(result)
题意:
输入洗牌次数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;
}
本文共计407个文字,预计阅读时间需要2分钟。
题意:输入商标次数K(K=20),输入54张牌每次洗入的位置(不是交换的位置),输出洗好的牌。
代码:pythondef shuffle_cards(K, positions): # 初始化牌堆 deck=list(range(1, 55)) # 洗牌过程 for _ in range(K): for pos in positions: deck.insert(pos, deck.pop(0)) return deck
输入示例K=20positions=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53]
输出结果result=shuffle_cards(K, positions)print(result)
题意:
输入洗牌次数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;
}

