拼多多笔试 骰子题
import java.util.*; import java.util.stream.Collectors; /** * @Author spike * @Date: 2020-07-28 23:18 */ public class Quiz { static int[][] dic = new int[][]{ {0,1,2,3,4,5}, {1,0,2,3,5,4}, {2,3,1,0,4,5}, {3,2,0,1,4,5}, {4,5,2,3,1,0}, {5,4,2,3,0,1} }; static int[][] p = new int[][] { {2,3,4,5}, {5,4,2,3}, {3,2,5,4}, {4,5,3,2} }; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[][] s = new int[n][6]; for (int i = 0; i < n; i++) { for (int j = 0; j < 6; j++) { s[i][j] = scanner.nextInt(); } } Map<String, Integer> map = new HashMap<>(); for (int[] sh : s) { for (int j = 0; j < 6; j++) { if (sh[j] == 1) { String t = "" + sh[dic[j][0]] + sh[dic[j][1]]; String po = ""; boolean b = false; for (int k = 0; k < 4; k++) { po = t; for (int l = 0; l < 4; l++) { int index = p[k][l]; po += sh[dic[j][index]]; } if (map.containsKey(po)) { map.put(po, map.get(po) + 1); b = true; break; } } if (!b) { map.put(po, 1); } } } } List<Integer> list = new ArrayList<>(map.values()); Collections.sort(list, (a,b)->b - a); System.out.println(map.size()); for (int i : list) { System.out.print(i + " "); } } }用了硬编码dic把index都转换成1在top的情况,然后遍历一下水平旋转的4种情况(也是硬编码p数组)
#拼多多##笔试题目#