首页 > 试题广场 >

Shuffling Machine (20)

[编程题]Shuffling Machine (20)
  • 热度指数:2713 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
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 casinos employ automatic shuffling machines . Your task is to simulate a shuffling machine.
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,
D1, D2, ..., D13,
J1, J2
where "S" stands for "Spade", "H" for "Heart", "C" for "Club", "D" for "Diamond", and "J" for "Joker". A given order is a permutation of distinct integers in [1, 54]. If the number at the i-th position is j, it means to move the card from position i to position j. For example, suppose we only have 5 cards: S3, H5, C1, D13 and J2. Given a shuffling order {4, 2, 5, 3, 1}, the result will be: J2, H5, D13, S3, C1. If we are to repeat the shuffling again, the result will be: C1, H5, S3, J2, D13.

输入描述:
Each input file contains one test case.  For each case, the first line contains a positive integer K (<= 20) which is the number of repeat times.  Then the next line contains the given order.  All the numbers in a line are separated by a space.


输出描述:
For each test case, print the shuffling results in one line.  All the cards are separated by a space, and there must be no extra space at the end of the line.
示例1

输入

2
36 52 37 38 3 39 40 53 54 41 11 12 13 42 43 44 2 4 23 24 25 26 27 6 7 8 48 49 50 51 9 10 14 15 16 5 17 18 19 1 20 21 22 28 29 30 31 32 33 34 35 45 46 47

输出

S7 C11 C10 C12 S1 H7 H8 H9 D8 D9 S11 S12 S13 D10 D11 D12 S3 S4 S6 S10 H1 H2 C13 D2 D3 D4 H6 H3 D13 J1 J2 C1 C2 C3 C4 D1 S5 H5 H11 H12 C6 C7 C8 C9 S2 S8 S9 H10 D5 D6 D7 H4 H13 C5
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int now[N],temp[N],order[N];//now[i]代表i位置的牌是什么
int main(){
    int k;
    scanf("%d",&k);
    for(int i = 1; i <=54; i++){
        scanf("%d",&order[i]);
        now[i] = i;
    }
    while(k--){
        for(int i = 1; i <= 54; i++){
            temp[i] = now[i];
        }
        for(int i = 1; i <= 54; i++){//移动位置
            now[order[i]] = temp[i];
        }
    }
    for(int i = 1; i <= 54; i++){
        if(i>1) printf(" ");
        if(now[i]<=13) printf("S%d",now[i]);
        else if(now[i]>13&&now[i]<=26) printf("H%d",now[i]-13);
        else if(now[i]>26&&now[i]<=39) printf("C%d",now[i]-26);
        else if(now[i]>39&&now[i]<=52) printf("D%d",now[i]-39);
        else printf("J%d",now[i]-52);
    }
    return 0;
}

发表于 2019-03-30 22:06:04 回复(0)

类似快速幂求法,

洗2次牌可以合并成1次,合并举例: 4 3 1 5 2(1先到4再到5)洗两次相当于 5 1 4 2 3洗一次.所以洗k次就可以两两合并从而大大减少洗牌次数




#include<bits/stdc++.h>

using namespace std;

 

vector<int> shuffling(const vector<int> &ori,const vector<int> &order){

    vector<int> res(55);

 

    for(int i=1;i<55;i++){

        res[order[i]]=ori[i];

    }

    return res;

    

}

 

vector<int> merg(const vector<int> &order){

    vector<int> res(55);

 

    for(int i=1;i<55;i++){

        res[i]=order[order[i]];

    }

    return res;

    

}

 

 

int main(){

    int r;

    cin>>r;

    

    vector<int> order(55);//1~54

    

    for(int i=1;i<55;i++){

        cin>>order[i];

    }

    

    

    //快速幂

    vector<int> res(55);

    for(int i=1;i<55;i++){

        res[i]=i;

    }

    

    while(r){

        if(r%2==0){

            order=merg(order);

            r/=2;

        }else{

            

            res=shuffling(res,order);

            r--;

        }

    }

    

    //输出

    for(int i=1;i<55;i++){

        int cas=(res[i]-1)/13;

        int num=res[i]-cas*13;

        

        switch(cas){

            case 0:

                cout<<"S";

                break;

            case 1:

                cout<<"H";

                break;

            case 2:

                cout<<"C";

                break;

            case 3:

                cout<<"D";

                break;

            case 4:

                cout<<"J";

                break;

        }

        

        cout<<num;

        if(i!=54)cout<<" ";

    }

    

    

    return 0;

}


发表于 2017-07-18 14:41:12 回复(0)
#include <iostream>
#include <vector>

using namespace std;

vector<int> shuffling(const vector<int> b, const vector<int> a)
{     vector<int> c(55);     for(int i=1;i<55;i++)         c[a[i]] = b[i];     return c;
}

vector<int> merge(const vector<int> a)
{     vector<int> b(55);     for(int i=1;i<55;i++)         b[i] = a[a[i]];     return b;
}

int main()
{     int N;     cin>>N;     vector<int> a(55);     for(int i=1;i<55;i++)         cin>>a[i];     vector<int> b(55);     for(int i=1;i<55;i++)         b[i] = i;     while(N)     {         if(N%2==0)         {             a = merge(a);             N /= 2;         }else{             b = shuffling(b, a);             N--;         }     }     for(int i=1;i<55;i++)     {         int C = (b[i]-1)/13;         int n = b[i]-C*13;         switch(C){             case 0:                 cout<<"S";                 break;             case 1:                 cout<<"H";                 break;             case 2:                 cout<<"C";                 break;             case 3:                 cout<<"D";                 break;             case 4:                 cout<<"J";                 break;         }         if(i==54)             cout<<n<<endl;         else             cout<<n<<" ";             }     return 0;
}


发表于 2018-03-10 01:07:15 回复(0)
#include<stdio.h>
int main()
{
	int K,i,j;
	int outcome[54];
	int order[54];
	int shuffle1[54],shuffle2[54];
	for(i=0;i<54;i++) shuffle2[i]=i;//shuffle2初始化,为0~53
	scanf("%d",&K);
	for(i=0;i<54;i++) scanf("%d",order+i);
	for(i=1;i<=K;i++){
		if(i%2){//从shuffle1和shuffle2之间交替洗牌,以i的奇偶性判断从哪个洗到另一个
			for(j=0;j<54;j++){
				shuffle1[order[j]-1]=shuffle2[j];
			}
		}
		else{
			for(j=0;j<54;j++) shuffle2[order[j]-1]=shuffle1[j];
		}
	}
	if(K%2) for(j=0;j<54;j++) outcome[j]=shuffle1[j];
	else for(j=0;j<54;j++) outcome[j]=shuffle2[j];//判断1和2哪个才是最终结果 
	for(j=0;j<54;j++){
		switch(outcome[j]/13){
			case 0:
			printf("S");
			break;
			case 1:
			printf("H");
			break;
			case 2:
			printf("C");
			break;
			case 3:
			printf("D");
			break;
			case 4:
			printf("J");
			break;
		}//输出卡牌的花色
		printf("%d",(outcome[j]%13)+1);//输出牌面数字
		if(j<53) putchar(' ');//输出空格
	}
	return 0;
}
			
	
//想了想二维数组可以简化逻辑:
#include<stdio.h>
int main()
{
	int K,i,j;
	int order[54];
	int shuffle[21][54];
	scanf("%d",&K);
	for(i=0;i<54;i++) shuffle[0][i]=i;
	for(i=0;i<54;i++) scanf("%d",order+i);
	for(i=1;i<=K;i++){
		for(j=0;j<54;j++){
			shuffle[i][order[j]-1]=shuffle[i-1][j];
		}
	}
	for(j=0;j<54;j++){
		switch(shuffle[K][j]/13){
			case 0:
			printf("S");
			break;
			case 1:
			printf("H");
			break;
			case 2:
			printf("C");
			break;
			case 3:
			printf("D");
			break;
			case 4:
			printf("J");
			break;
		}
		printf("%d",(shuffle[K][j]%13)+1);
		if(j<53) putchar(' ');
	}
	return 0;
}

编辑于 2017-06-24 23:05:30 回复(0)
#include <stdio.h>


int c[600];
int a[600];
int b[600];

//a[]:S1,S2...   b[]:6,32...  c[]:ans
void shuffle()
{
int i,t;
for(i=1;i<55;i++)
{
t = b[i];
c[t] = a[i];
}
for(i=1;i<55;i++)
{
a[i] = c[i];
}
}

void card_init()
{
int i;
for(i=1;i<=54;i++)
{
a[i] = i;
}
}

char get_color(int n)
{
char ch;
if((n-1)/13 == 0)
{
ch = 'S';
}
else if((n-1)/13 == 1)
{
ch = 'H';
}
else if((n-1)/13 == 2)
{
ch = 'C';
}
else if((n-1)/13 == 3)
{
ch = 'D';
}
else
{
ch = 'J';
}
return ch;
}


//36 52 37 38 3 39 40 53 54 41 11 12 13 42 43 44 2 4 23 24 25 26 27 6 7 8 48 49 50 51 9 10 14 15 16 5 17 18 19 1 20 21 22 28 29 30 31 32 33 34 35 45 46 47

int main()
{
    int n,i;
    char ch;
    scanf("%d",&n);
    for(i=1;i<=54;i++)
    {
    scanf("%d",&(b[i]));
    }
    
    card_init();
    
    for(i=0;i<n;i++)
    {
    shuffle();
    }
    
    for(i=1;i<=54;i++)
    {
    ch = get_color(c[i]);
    printf("%c",ch);
    printf("%d",(c[i])%13==0?13:(c[i])%13);
    if(i != 54)
    {
    printf(" ");
    }
    }
    
    return 0;
发表于 2017-03-10 13:31:02 回复(0)
啥头像
给一个笨一点的解:
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>

using namespace std;

int main()
{
    // 初始化cards和读入随机数
    string str[4] = {"S", "H", "C", "D"};
    vector<string> cards(55); int index = 1; int j;
    string preStr, tempStr; char ch[3];
    for(int i=0; i<4; i++) {
        preStr = str[i];
        for(j=1; j<=13; j++) {
            sprintf(ch, "%d", j); tempStr = preStr + ch;
            cards[index++] = tempStr;
        }
    }
    cards[index++] = "J1";
    cards[index] = "J2";
    int K; scanf("%d", &K);
    int randomInt[55];
    for(int i=1; i<=54; i++) {
        scanf("%d", &randomInt[i]);
    }

    // 随机化处理
    int i; vector<string> tempCards(55);
    for(int k=0; k<K; k++) {
        for(i=1; i<=54; i++) {
            j=randomInt[i];
            tempCards[j] = cards[i];
        }
        cards = tempCards;
    }

    // 输出结果
    cout << cards[1];
    for(i=2; i<=54; i++) {
        cout << " " << cards[i];
    }
    return 0;
} 


发表于 2015-12-05 22:58:08 回复(0)
#include<bits/stdc++.h>
using namespace std;

const int Max=54;
char mp[5]={'S','H','C','D','J'};
int start[Max],End[Max],Next[Max];

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=54;i++){
		start[i]=i;
	}
	for(int i=1;i<=54;i++){
		cin>>Next[i];
	}
	for(int i=0;i<n;i++){
		for(int j=1;j<=Max;j++){
			End[Next[j]]=start[j];
		}
		for(int k=1;k<=Max;k++){
			start[k]=End[k];
		}
	}
	for(int i=1;i<=54;i++){
		if(i!=1) cout<<" ";
		start[i]--;
		cout<<mp[start[i]/13]<<start[i]%13+1;
	}
	return 0;
}

发表于 2022-11-03 16:59:34 回复(0)
//shuffling mac
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
using namespace std;
int cards_order[55]={0};
vector<vector<int> >result(1);
int main(){
	int k;cin>>k;
	for(int i=1;i<=54;i++)cin>>cards_order[i];
	for(int i=0;i<=54;i++)result[0].push_back(i);//the initial states
	//cout<<"stae1"<<endl;
	for(int i=1;i<=k;i++){
		result.push_back(result[i-1]);
		for(int j=1;j<=54;j++)
				result[i][cards_order[j]]=result[i-1][j];
	}
	//cout<<"test"<<endl;//
	int gg=result.size();int tem;
	for(int i=1;i<=54;i++){
		tem=result[gg-1][i];
		if(tem<=13)if(tem==13) printf("S%d",13);else printf("S%d",tem%13);
		else if(tem<=26)if(tem==26)printf("H%d",13);else printf("H%d",tem%13);
		else if(tem<=39)if(tem==39)printf("C%d",13);else printf("C%d",tem%13);
		else if(tem<=52)if(tem==52)printf("D%d",13);else printf("D%d",tem%13);
		else printf("J%d",tem-52);
		if(i<54)cout<<" ";
	}
	
	return 0;
}

发表于 2021-08-18 21:45:07 回复(0)
//开始用string 数组,最后发现不能直接用等号给它赋值,要用for循环一个一个给string赋值。。。
//然后用了vector<string>s,就可以直接s=....。operator=和assign都是深拷贝,不用担心数据修改问题。
//vector如果没指明大小,只能用push_back,声明大小后可以用数组的形式赋值,s[i]="";
//看到上面有大神说了类似于快速幂的方式来简化,感觉还不错
#include<iostream>
(720)#include<vector>
#include<string>
using namespace std;
int main() {
	int n;
	cin >> n;
	int order[55];
	for (int i = 1; i < 55; i++) {
		cin >> order[i];
	}
	vector<string>initial(55);
	for (int i = 1; i < 55; i++) {
		if (i <= 13) {
			initial[i]="S" + to_string(i);
		}
		else if (i <= 26) {
			initial[i] = "H" + to_string(i - 13);
		}
		else if (i <= 39) {
			initial[i] = "C" + to_string(i - 26);
		}
		else if (i <= 52) {
			initial[i] = "D" + to_string(i - 39);
		}
		else if (i == 53) {
			initial[i] = "J1";
		}
		else {
			initial[i] = "J2";
		}
	}
	for (int i = 0; i < n; i++) {
		vector<string> result(55);
		for (int j = 1; j < 55; j++) {
			result[order[j]] = initial[j];
		}
			initial = result;
	}
	for (int i = 1; i < 55; i++) {
		if (i != 1) { printf(" "); }
		printf("%s", initial[i].c_str());
	}
}


发表于 2020-03-23 14:33:28 回复(0)
//Shuffling Machine (20分)
#include <iostream>
(720)#include <vector>
#include <cstring>

using namespace std;
vector<string> arrays;
string change[1000];
char ss[5] = {'S', 'H', 'C', 'D', 'J'};
int k, orde[1000];

int main() {
    arrays.push_back("x");
    for (int i = 0; i < 5; i++) {
        if (i != 4)
            for (int j = 1; j <= 13; j++)
                arrays.push_back(ss[i] + to_string(j));
        else {
            arrays.push_back(ss[i] + to_string(1));
            arrays.push_back(ss[i] + to_string(2));
        }
    }
    memset(orde, 0, sizeof(orde));
    cin >> k;
    for (int i = 1; i <= 54; i++) {
        int number;
        cin >> number;
        orde[i] = number;
    }
    for (int i = 1; i <= 54; i++) {
        int index = i;
        for (int j = 0; j < k; j++)
            index = orde[index];
        change[index] = arrays[i];
    }
    cout << change[1];
    for (int i = 2; i <= 54; i++)
        cout << " " << change[i];
}

发表于 2020-03-02 17:52:18 回复(0)

用两个字符串数组解决,一个存放洗牌后的,一个临时接受洗牌的即可

#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;

string str1[60],str2[60];
int num[55];
void init() {//初始化,str1存放,str2其实是分配空间
    char ch[5] = { 'S','H','C','D','J' };
    for (int i = 1; i <= 54; i++) {
        if (i <= 13)                 str1[i] = ch[0] + to_string(i);
        else if (i > 13 && i <= 26)  str1[i] = ch[1] + to_string(i - 13);
        else if (i > 26 && i <= 39)  str1[i] = ch[2] + to_string(i - 26);
        else if (i > 39 && i <= 52)  str1[i] = ch[3] + to_string(i - 39);
        else if (i > 52 && i <= 54)  str1[i] = ch[4] + to_string(i - 52);
    }
}
int main() {
    init();

    int n = 0;//洗牌次数
    cin >> n;
    for (int i = 1; i <= 54; i++) {//num存储顺序
        cin >> num[i];
    }

    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= 54; j++) {
            str2[num[j]] = str1[j];//把str第j位存储到str的dinum[j]位
        }
        for (int j = 1; j <= 54; j++)str1[j] = str2[j];
    }
    for (int i = 1; i <= 54; i++) {
        if (i != 1)cout << " ";
        cout << str1[i];
    }
    cout << endl;
    system("pause");
    return 0;
}
发表于 2019-10-15 17:34:50 回复(0)
惊了 不知道为啥不能直接用strcpy(card,card1)和strcpy(card1,empty)...
#include <iostream>
#include <cstring>
using namespace std;

const int maxn = 54;


int main(){
    char card[maxn];
    int position[maxn];
    for(int i = 1;i <= maxn;i++){
        if(i <= 13){ 
            card[i] = 'S';
            position[i] = i;
        }
        if(i > 13 && i <= 26){
            card[i] = 'H';
            position[i] = i - 13;
           
        }
        if(i > 26 && i <= 39){
            card[i] = 'C';
            position[i] = i - 26;
          
        }
        if(i > 39 && i <= 52){
            card[i] = 'D';
            position[i] = i - 39;
            
        }
        if(i > 52 && i <= 54){
            card[i] = 'J';
            position[i] = i - 52;
        }
    }
    int k;
    int p[maxn];
    char card1[maxn];
    int position1[maxn];
    cin >> k;
    for(int i = 1;i <= maxn;i++){
        cin >> p[i];
    }
    
    for(int i = 0;i < k;i++){
        for(int j = 1;j <= maxn;j++){
            
            card1[p[j]] = card[j];
            position1[p[j]] = position[j];
            
        }
        if(i == k - 1) break;
        else{
            ;
            for(int j = 1;j <= maxn;j++){
                position[j] = position1[j];
                position1[j] = 0;
                card[j] = card1[j];
                card1[j] = '\0';
            }
            
            
        }
    }
    
    for(int i = 1;i <= maxn;i++){
        cout << card1[i] << position1[i];
        if(i != maxn) cout << " ";
    }
    
    return 0;
}


发表于 2019-09-02 16:30:03 回复(0)
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;


int main() {
	int a[55],n, num;	
	vector <string> c = { "0" ,"S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13","H1" ,"H2" ,"H3" ,"H4" ,"H5" ,"H6" ,"H7" ,"H8" ,"H9" ,"H10" ,"H11" ,"H12" ,"H13" ,"C1" ,"C2" ,"C3" ,"C4" ,"C5" ,"C6" ,"C7" ,"C8" ,"C9" ,"C10" ,"C11" ,"C12" ,"C13" ,"D1" ,"D2" ,"D3" ,"D4" ,"D5" ,"D6" ,"D7" ,"D8" ,"D9" ,"D10" ,"D11" ,"D12" ,"D13" ,"J1" ,"J2" } ;
	vector <string> b(55);
	vector<string> d(c.begin(), c.end());
	cin >> n;
	for (int i = 1; i < 55; i++)
	{	
		cin >>num;
		a[i] = num;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 1; j < 55;j++)
		{
			b[a[j]] = c[j];
		}
		c.assign(b.begin(),b.end());
	}
	for (int i = 1; i < 54; i++)
	{
		cout << b[i] << " ";
	}
	cout << b[54];
	return 0;
}

发表于 2019-08-12 14:06:54 回复(1)
//很简单的题,做了几个小时,下次做题前一点要想清楚再开打。。。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<vector>
using namespace std; 
const int maxn = 60;
vector<string>pai;
int opr[maxn];
int cup1[maxn];
int cup2[maxn];
int n;        
int *tcup = cup1, *fcup=cup2;
void init(){
    cin >> n;
    for (int i = 1; i <= 13; i++) pai.push_back("S" + to_string(i));
    for (int i = 1; i <= 13; i++) pai.push_back("H" + to_string(i));
    for (int i = 1; i <= 13; i++) pai.push_back("C" + to_string(i));
    for (int i = 1; i <= 13; i++) pai.push_back("D" + to_string(i));
    pai.push_back("J1"), pai.push_back("J2");
    for (int i = 0; i < 54; i++) cin >> opr[i];
    for (int i = 0; i < 54; i++) cup1[i] = cup2[i] = i;
}
void change(){
    for (int i = 0; i < 54; i++){
        int j = opr[i] - 1;
        fcup[j] = tcup[i];
    }
    swap(tcup, fcup);
}
int main(){    
    init();
    while (n--) change();
    for (int i = 0; i < 53; i++)cout << pai[tcup[i] ]<< " ";
    cout << pai[tcup[53]] << endl;
    return 0;
}
发表于 2018-12-18 09:21:44 回复(0)
def suff(a,b):
    tem = [None]*len(a)
    for i in range(0,len(b)):
        tem[b[i]-1] = a[i]
    return tem    
    
lst = ['S1','S2','S3','S4','S5','S6','S7','S8','S9','S10','S11','S12','S13',
       'H1','H2','H3','H4','H5','H6','H7','H8','H9','H10','H11','H12','H13',
       'C1','C2','C3','C4','C5','C6','C7','C8','C9','C10','C11','C12','C13',
       'D1','D2','D3','D4','D5','D6','D7','D8','D9','D10','D11','D12','D13',
       'J1','J2']
n = input()
n = int(n)
num = list(map(int,input().split()))
out = list(lst)
for k in range(0,n):
    out = suff(out,num)
print(' '.join(out))

发表于 2018-12-03 22:36:53 回复(0)
N=int(input())
L=[0]+list(map(int,input().split()))
S=[list(range(55)) for _ in range(2)]
def int2str(x):
    s=['S','H','C','D','J']
    a,b=(x-1)//13,(x-1)%13+1
    return s[a]+str(b)
for i in range(N):
    for j in range(1,55):
        S[(i+1)%2][L[j]]=S[i%2][j]
print(' '.join(map(int2str,S[N%2][1:])))

发表于 2018-09-01 19:24:15 回复(0)
思路:就是输出卡牌的乱序。
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void Init(vector<string> & v)
{
    v.resize(54);
    string flower[] = { "S","H","C","D" };
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 13; j++)
        {
            v[(i*13)+(j)] = flower[i];
            if (j + '0' + 1 <= '9')
                v[(i * 13) + (j)] += j + '0' + 1;
            else
            {
                v[(i * 13) + (j)] += "1";
                v[(i * 13) + (j)] += j + '0' + 1 - 10;
            }
                
        }
    }
    v[52] = "J1";
    v[53] = "J2";
}

void Repeat(vector<int> index, vector<string>& cards)
{
    string tmp;
    vector<string> rlt(54);
    for (int i = 0; i < index.size(); i++)
    {
        tmp = cards[i];
        //cards[i] = cards[index[i] - 1];
        rlt[index[i] - 1] = tmp;
    }
    cards = rlt;
}


int main()
{
    int n;
    cin >> n;
    vector<string> cards;
    Init(cards);
    vector<int> index(54);
    for (int i = 0; i < 54; i++)
    {
        cin >> index[i];
    }
    for (int i = 0; i < n; i++)
    {
        Repeat(index, cards);
    }
    for (int i = 0; i < cards.size(); i++)
    {
        cout << cards[i];
        if (i != cards.size() - 1)
            cout << " ";
        else
            cout << endl;
    }
    system("pause");
    return 0;
}

发表于 2018-08-25 19:44:19 回复(0)

#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
struct poker {
    string id = "";
    int pos=0;
} pokers[55];
int cmp(poker p1, poker p2) {
    return p1.pos < p2.pos;
}
int main() {

    //vector<string>dic(54, "");
    char dic[5] = { 'S','H','C','D','J' };
    for (int i = 0; i<5; i++) {
        if (i < 4) {
            for (int j = 1; j <= 13; j++) {
                pokers[i * 13 + j].id.push_back(dic[i]);
                if(j>9){
                     pokers[i * 13 + j].id.push_back('1');
                      pokers[i * 13 + j].id.push_back('0'+j%10);
                }else{
                     pokers[i * 13 + j].id.push_back('0'+j);
                }

            }
        }
        else {
            pokers[53].id = "J1";
            pokers[54].id = "J2";
        }
    }

    int repeat;
    cin >> repeat;
    vector<int>order(54);
    for (int i = 0; i < 54; i++) {
            cin >> order[i];
    }
    for (int j = 0; j < repeat; j++) {
        for (int i = 1; i < 55; i++) {
            pokers[i].pos = order[i-1];
        }
        sort(pokers, pokers + 55,cmp);
    }
    for (int i = 1; i < 55; i++) {
        cout<< pokers[i].id;
        if(i<54){
            cout<<" ";
        }
    }




    return 0;
}
发表于 2018-07-19 16:42:23 回复(0)
k = int(input())
od = list(map(int, input().split()))
card = []
suit=['S', 'H', 'C', 'D']
for i in range(52):
    card.append(suit[i//13]+str(i%13+1))
card.extend(['J1','J2'])
a = sorted(zip(od,list(range(54))))
a = [x[1] for x in a]
for i in range(k):
    card = [card[x] for x in a]
print(' '.join(card))

发表于 2018-04-19 15:48:17 回复(0)
#define MAXN 54
#include<iostream>
using namespace std;

int main()
{
    int repat;
    cin >> repat;

    int change[MAXN+1] = {0}, south[MAXN+1] = {0};
    for(int i = 1; i <= MAXN; i++)
    {
        cin >> change[i];
        south[i] = i;
    }
    
    for(int j = 0; j < repat; j++)
    {
        int temp[MAXN+1] = {0};
        for(int i = 1; i <=MAXN; i++)
            temp[change[i]] = south[i];
        for(int i = 1; i <=MAXN; i++)
            south[i] = temp[i];
    }

    //输出
    for(int i = 1; i <= MAXN; i++)
    {
        if((south[i]-1) / 13 == 0)
            cout << "S";
        else if((south[i]-1) / 13 == 1)
            cout << "H";
        else if((south[i]-1) / 13 == 2)
            cout << "C";
        else if((south[i]-1) / 13 == 3)
            cout << "D";
        else if((south[i]-1) / 13 == 4)
            cout << "J";
        cout  << (south[i]-1)%13+1;
        if(i != MAXN)
            cout << " ";
    }

    system("pause");
    return 0;
}
发表于 2018-03-01 21:47:46 回复(0)