原题
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", ×);
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;
}