PTA----简单模拟---A1042

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805442671132672

题目大意:有54张牌,编号1-54,从小到大排序。这些牌按初始排列给定花色,从左到右,13张S,13张H,13张C,13张D,两张J

接下来执行一种操作,这种操作将牌的位置改变为制定位置,操作执行K次。

分析:用两个数组start[ ],end[ ],一个记录操作开始前的情况,一个记录操作后的情况,每次操作完,用end 覆盖 start。

代码:

#include<iostream>
#include<cstdio>
using namespace std;
#include<algorithm>
#include<cmath>
#include<set> 
#include<map>
#include<string> 
#include<cstring>
#include<vector>
#include<cstdlib> 
#define ll long long int 
char mp[5]={'S','H','C','D','J'};
int main()
{
 	int n;
	cin>>n;
	int start[55],next[55],end[55];
	for(int i=1;i<=54;i++)
		start[i]=i;
	for(int i=1;i<=54;i++)    //next 储存操作
		cin>>next[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=54;j++){
			end[next[j]]=start[j];
		}
		for(int k=1;k<=54;k++)    //覆盖
			start[k]=end[k];
	}
	for(int i=1;i<=54;i++)
	{
		start[i]--;    //这里start-1,是因为,当start=13时,是可以被13整除的,之后加+1就有错误
		printf("%c%d",mp[start[i]/13],start[i]%13+1);
		if(i<54)	printf(" ");
	}
	return 0;
 } 

猜你喜欢

转载自blog.csdn.net/qq_40725780/article/details/81606923