美文网首页
骰子旋转

骰子旋转

作者: xiaohei_e853 | 来源:发表于2022-03-03 01:13 被阅读0次
    package test;
    
    import java.util.Arrays;
    import java.util.Scanner;
    
    public class OverTest {
        public static void main(String[] args) {
    
    
            Scanner scanner = new Scanner(System.in);
            String s = scanner.nextLine();
            char[] chars = s.toCharArray();
    
            int[] origin = {1,2,3,4,5,6};
            //L
            int[] left = {5,6,3,4,2,1};
            //R
            int[] right = {6,5,3,4,1,2};
            //F
            int[] front = {1,2,5,6,4,3};
            //B
            int[] back = {1,2,6,5,3,4};
            //A
            int[] a = {4,3,1,2,5,6};
            //C
            int[] c = {3,4,2,1,5,6};
    
    //
            int[] input = origin;
    
            for(int i=0;i<chars.length;i++){
    
                char tmp = chars[i];
                //左转origin[0]-->origin[5],origin[1]-->origin[4],origin[4]-->origin[0],origin[5]-->origin[1],
                if('L'==tmp){
                    ///
    
                    //int[] origin = {1,2,3,4,5,6};
                    //        //L
                    //        int[] left = {5,6,3,4,2,1};
    
                    //
                    int[] temp = input.clone();
                    swap(input,temp,0,5);
                   // System.out.println(Arrays.toString(input));
                    swap(input,temp,1,4);
                   // System.out.println(Arrays.toString(input));
                    swap(input,temp,4,0);
                  //  System.out.println(Arrays.toString(input));
                    swap(input,temp,5,1);
                  //  System.out.println(Arrays.toString(input));
    
    
    
    
                }
    
                if('R'==tmp){
                    ///
    
                    //int[] origin = {1,2,3,4,5,6};
                    //        //L
                    //        int[] right = {6,5,3,4,1,2};
    
                    //
                    int[] temp = input.clone();
                    swap(input,temp,0,4);
                    swap(input,temp,1,5);
                    swap(input,temp,4,1);
                    swap(input,temp,5,0);
                    System.out.println(Arrays.toString(input));
                }
    
                if('F'==tmp){
                    ///
    
                    //int[] origin = {1,2,3,4,5,6};
                    //        //L
                    //        f = {1,2,5,6,4,3};
    
                    //
                    int[] temp = input.clone();
                    swap(input,temp,2,5);
                    swap(input,temp,3,4);
                    swap(input,temp,4,2);
                    swap(input,temp,5,3);
                    System.out.println(Arrays.toString(input));
                }
    
                if('B'==tmp){
                    ///
    
                    //int[] origin = {1,2,3,4,5,6};
                    //        //L
                    //        int[] back = {1,2,6,5,3,4};
    
                    //
                    int[] temp = input.clone();
                    swap(input,temp,2,4);
                    swap(input,temp,3,5);
                    swap(input,temp,4,3);
                    swap(input,temp,5,2);
                    System.out.println(Arrays.toString(input));
                }
    
                if('A'==tmp){
                    ///
    
                    //int[] origin = {1,2,3,4,5,6};
                    //        //L
                    //        a = {4,3,1,2,5,6};
    
                    //
                    int[] temp = input.clone();
                    swap(input,temp,0,2);
                    swap(input,temp,1,3);
                    swap(input,temp,2,1);
                    swap(input,temp,3,0);
                    System.out.println(Arrays.toString(input));
                }
    
                if('C'==tmp){
                    ///
    
                    //int[] origin = {1,2,3,4,5,6};
                    //        //L
                    //       int[] c = {3,4,2,1,5,6};
    
                    //
    
                    int[] temp = input.clone();
                    swap(input,temp,0,3);
                    swap(input,temp,1,2);
                    swap(input,temp,2,0);
                    swap(input,temp,3,1);
                    System.out.println(Arrays.toString(input));
                }
            }
    
    
        }
    
        public static void swap(int[] input,int[] temp, int i,int j){
            //
            //int[] origin = {1,2,3,4,5,6};
            //        //L
            //        int[] left = {5,6,3,4,2,1};
            input[j] = temp[i];
    
        }
    }
    
    
    
    
    
    

    相关文章

      网友评论

          本文标题:骰子旋转

          本文链接:https://www.haomeiwen.com/subject/utlyrrtx.html