1042. Shuffling Machine (20)

原题

1042. Shuffling Machine (20)

代码

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

void shuffle(char cards[55][5], int times, int shuf[55]);
int main(int argc, const char * argv[]) {
    char cards[55][5];
    for(int i = 0; i < 4; i++){
        for(int j = 1; j <= 13; j++){
            switch(i){
                case 0: sprintf(cards[i* 13 + j], "S%d", j);
                    break;
                case 1: sprintf(cards[i* 13 + j], "H%d", j);
                    break;
                case 2: sprintf(cards[i* 13 + j], "C%d", j);
                    break;
                case 3: sprintf(cards[i* 13 + j], "D%d", j);
                    break;
            }
        }
    }
    strcpy(cards[53], "J1");
    strcpy(cards[54], "J2");
    int times;
    scanf("%d", &times);

    int shuf[55];
    for(int i = 1; i <= 54; i++){
        scanf("%d", shuf + i);
    }

    shuffle(cards, times, shuf);
    printf("%s", cards[1]);
    for(int i = 2; i <= 54; i++){
        printf(" %s", cards[i]);
    }
    return 0;
}
void shuffle(char cards[55][5], int times, int shuf[55]){
    char copy[55][5];
    for(int i = 0; i < times; i++){
        for(int j = 1; j < 55; j++){
            strcpy(copy[shuf[j]], cards[j]);
        }
        for(int j = 1; j < 55; j++){
            strcpy(cards[j], copy[j]);
        }
    }
    return;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值