Article directory
Question 185.pat Grade A Exercise - 1042 Shuffling Machine (20 points)
1. The topic
2. Problem solving
This question allows you to shuffle the cards, and each round of shuffling puts the cards in the current position in the position specified by the input rules.
#include <bits/stdc++.h>
using namespace std;
string cards[21][55];
int rule[55];
int main()
{
for(int i=0,j=1;i<5;i++)
{
if(i<4)
{
for(int k=1;k<=13;k++)
{
if(i==0)
{
cards[0][j]="S";
}
else if(i==1)
{
cards[0][j]="H";
}
else if(i==2)
{
cards[0][j]="C";
}
else if(i==3)
{
cards[0][j]="D";
}
string post=to_string(k);
cards[0][j]+=post;
j++;
}
}
else
{
for(int k=1;k<=2;k++)
{
cards[0][j]="J";
string post=to_string(k);
cards[0][j]+=post;
j++;
}
}
}
int K;
cin>>K;
for(int i=1;i<=54;i++)
{
scanf("%d",&rule[i]);
}
for(int i=0;i<K;i++)
{
for(int j=1;j<=54;j++)
{
cards[i+1][rule[j]]=cards[i][j];
}
if(i==K-1)
{
for(int j=1;j<=54;j++)
{
if(j>1)
{
putchar(' ');
}
cout<<cards[i+1][j];
}
}
}
}