PAT A1042 Shuffling Machine (20分)


如何表示花色:1.string,2.char数组,3.char+数字;
1..N由于没有零位在进行整除和余数运算时使用 (num-1)来变成0...N-1最后记得加1

#include <cstdio>
using namespace std;
char card[5] = {'S','H','C','D','J'};

int main(){
//     freopen("data.txt","r",stdin);
    int repeat;
    scanf("%d",&repeat);
    int temp[55];
    int result[55] ;
    int resulttemp[55];
    int id;
    for(int i = 1;i<=54;i++){
            scanf("%d",&id);
            temp[i] = id;
    }
    //初始化result
    for(int i = 0;i<=54;i++){
        result[i] = i;
    }
    for(int i= 0;i<repeat;i++){
        for(int j = 1;j<=54;j++){
            resulttemp[j] = result[j];
        }
        for(int j = 1;j<=54;j++){
            result[temp[j]] = resulttemp[j];
        }
    }
    for(int i = 1;i<=54;i++){
        printf("%c%d",card[(result[i]-1)/13],(result[i]-1)%13 +1);
        if(i!=54) printf(" ");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/shuibeng/p/13598423.html