1 题目
2 代码
import java.util.Arrays;
import java.util.Scanner;
public class A1042 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int K = sc.nextInt();
int[] shuffle = new int[55];
int[] card = new int[55];
char[] mp = {'S','H','C','D','J'};
for (int i = 1; i <= 54; i++) {
shuffle[i] = sc.nextInt();
card[i] = i;
}
for (int i = 1; i <= K; i++) {
int[] temp = new int[55]; // 采用一个中间数组
for (int j = 1; j <= 54; j++) {
temp[shuffle[j]] = card[j];
}
card = temp;
}
System.out.print(mp[(card[1] - 1) / 13] +""+((card[1] - 1) % 13 + 1));
for (int i = 2; i <=54 ; i++) {
System.out.print(" "+mp[(card[i] - 1) / 13] +""+((card[i] - 1) % 13 + 1));
}
}
}
3 要点
(1)洗牌的规则可以要遍历多遍,因此可以借助中间数组保存每一遍后牌的排列情况。
(2)牌初始大小和排列为1-54,牌的花色和大小的关系如下:mp[(card[1] - 1) / 13] 和((card[1] - 1) % 13 + 1)
。