jiakh9465 2022-05-31 04:29 采纳率: 100%
浏览 388
已结题

设计到算数的问题,求解答

有这样一段java代码

    public static void main(String[] args) {
        int state = 8688201;
        int index = 101;
        for (int i = 1; i < 11; i++) {
            int a1 = state & ((int) Math.pow(8, ((index * 10 + i - 1) % 10)) * 7);
            int a2 = (int) Math.pow(8, ((index * 10 + i - 1) % 10));
            int stateDecode = a1 / a2;
            System.out.println("index:" + (index * 10 + i) + ",stateDecode:" + stateDecode);
        }

    }

可以得到1011到1020的stateDecode,运行结果:

index:1011,stateDecode:1
index:1012,stateDecode:1
index:1013,stateDecode:1
index:1014,stateDecode:1
index:1015,stateDecode:1
index:1016,stateDecode:1
index:1017,stateDecode:1
index:1018,stateDecode:4
index:1019,stateDecode:0
index:1020,stateDecode:0

反之,要是已知1011到1020的stateDecode,如何得到state?

  • 写回答

13条回答 默认 最新

  • WaitIKnowYou 2022-05-31 09:11
    关注

    你好 可以得到答案了 有啥看不懂的问

    img

    package Answer7731784;
    
    import java.util.Arrays;
    import java.util.HashMap;
    
    public class Answeer7731784 {
        public static void main(String[] args) {
            int state = 8688201;
            int index = 101;
            HashMap<Integer, Integer> hm = new HashMap<>();
    
            for (int i = 1; i < 11; i++) {
                int a1 = state & ((int) Math.pow(8, ((index * 10 + i - 1) % 10)) * 7);
    
                int a2 = (int) Math.pow(8, ((index * 10 + i - 1) % 10));
                int stateDecode = a1 / a2;
                System.out.println("index:" + (index * 10 + i) + ",stateDecode:" + stateDecode);
                hm.put((index * 10 + i), stateDecode);
    
            }
            int getState = getState(index, hm);
            System.out.println("state="+getState);
        }
    
        private static int getState(int index, HashMap<Integer, Integer> hm) {
            System.out.println("输入原有的10个映射关系");
            System.out.println(hm);
            System.out.println("开始运算:");
            int[] arry = new int[11];
            boolean flag = true;
            int getState = 0;
            while (flag) {
                int count = 1;
                for (int i = 1; i < 11; i++) {
                    int stateD = hm.get(index * 10 + i);
                    int a2 = (int) Math.pow(8, ((index * 10 + i - 1) % 10));
                    int a1 = stateD * a2;
                    while (true) {
                        int a = getState & ((int) Math.pow(8, ((index * 10 + i - 1) % 10)) * 7);
                        if (a == a1) {
                            arry[i] = getState;
                            break;
                        }
                        getState++;
                    }
                }
                System.out.println(Arrays.toString(arry));
                for (int i = 1; i < 10; i++) {
                    if (arry[i] == arry[i + 1]) {
                        count++;
                    }
                }
                if(count==10)
                    flag=false;
                
            }
            System.out.println("得到结果: ");
            return getState;
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(12条)

报告相同问题?

问题事件

  • 系统已结题 6月8日
  • 已采纳回答 5月31日
  • 创建了问题 5月31日

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了