• 一个奇怪的数字


    package test;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class KaoShi
    {    
        /*
         * 1到9,9个数字,组成一个9位数
         * 该9位数要求如下:
         * 每个数只能用1次
         * 从左侧取1位数所成的数字,可以被1整除
         * 从左侧取2位数所成的数字,可以被2整除
         * ……
         * 从左侧取9位数所成的数字,可以被9整除
         */
        
        public static void main(String[] args)
        {
            int[] a = {1,2,3,4,5,6,7,8,9};
    
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");//设置日期格式
            System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
    
            for (int i1 = 0; i1 < a.length; i1++)
            {
                for (int i2 = 0; i2 < a.length; i2++)
                {
                    for (int i3 = 0; i3 < a.length; i3++)
                    {
                        for (int i4 = 0; i4 < a.length; i4++)
                        {
                            for (int i5 = 0; i5 < a.length; i5++)
                            {
                                for (int i6 = 0; i6 < a.length; i6++)
                                {
                                    for (int i7 = 0; i7 < a.length; i7++)
                                    {
                                        for (int i8 = 0; i8 < a.length; i8++)
                                        {
                                            for (int i9 = 0; i9 < a.length; i9++)
                                            {
                                                if (a[i1] != a[i2] &&
                                                    a[i1] != a[i3] &&
                                                    a[i1] != a[i4] && 
                                                    a[i1] != a[i5] && 
                                                    a[i1] != a[i6] &&
                                                    a[i1] != a[i7] && 
                                                    a[i1] != a[i8] && 
                                                    a[i1] != a[i9] && 
                                                    
                                                    a[i2] != a[i3] &&
                                                    a[i2] != a[i4] && 
                                                    a[i2] != a[i5] && 
                                                    a[i2] != a[i6] &&
                                                    a[i2] != a[i7] && 
                                                    a[i2] != a[i8] && 
                                                    a[i2] != a[i9] &&
                                                    
                                                    a[i3] != a[i4] && 
                                                    a[i3] != a[i5] && 
                                                    a[i3] != a[i6] &&
                                                    a[i3] != a[i7] && 
                                                    a[i3] != a[i8] && 
                                                    a[i3] != a[i9] &&
                                                    
                                                    a[i4] != a[i5] && 
                                                    a[i4] != a[i6] &&
                                                    a[i4] != a[i7] && 
                                                    a[i4] != a[i8] && 
                                                    a[i4] != a[i9] &&
                                                    
                                                    a[i5] != a[i6] &&
                                                    a[i5] != a[i7] && 
                                                    a[i5] != a[i8] && 
                                                    a[i5] != a[i9] &&
                                                    
                                                    a[i6] != a[i7] && 
                                                    a[i6] != a[i8] && 
                                                    a[i6] != a[i9] &&
                                                    
                                                    a[i7] != a[i8] && 
                                                    a[i7] != a[i9] &&
                                                    
                                                    a[i8] != a[i9])
                                                {
                                                    int int1 = a[i1];
                                                    
                                                    int int2 = a[i1] * 10 +
                                                               a[i2];
                                                    
                                                    int int3 = a[i1] * 100 + 
                                                               a[i2] * 10 + 
                                                               a[i3];
                                                    
                                                    int int4 = a[i1] * 1000 + 
                                                               a[i2] * 100 + 
                                                               a[i3] * 10 +
                                                               a[i4];
                                                    
                                                    int int5 = a[i1] * 10000 + 
                                                               a[i2] * 1000 + 
                                                               a[i3] * 100 +
                                                               a[i4] * 10 + 
                                                               a[i5];
                                                    
                                                    int int6 = a[i1] * 100000000 + 
                                                               a[i2] * 10000000+ 
                                                               a[i3] * 1000000+
                                                               a[i4] * 100000+ 
                                                               a[i5] * 10000+ 
                                                               a[i6];
                                                    
                                                    int int7 = a[i1] * 1000000 + 
                                                               a[i2] * 100000 + 
                                                               a[i3] * 10000 +
                                                               a[i4] * 1000 + 
                                                               a[i5] * 100 + 
                                                               a[i6] * 10+
                                                               a[i7];
                                                    
                                                    int int8 = a[i1] * 10000000 + 
                                                               a[i2] * 1000000 + 
                                                               a[i3] * 100000 +
                                                               a[i4] * 10000 + 
                                                               a[i5] * 1000 + 
                                                               a[i6] * 100 +
                                                               a[i7] * 10 + 
                                                               a[i8];
                                                    
                                                    int int9 = a[i1] * 100000000 + 
                                                               a[i2] * 10000000+ 
                                                               a[i3] * 1000000+
                                                               a[i4] * 100000+ 
                                                               a[i5] * 10000+ 
                                                               a[i6] * 1000+
                                                               a[i7] * 100+ 
                                                               a[i8] * 10+ 
                                                               a[i9];
    
                                                    
                                                    
                                                    if (int1 % a[0] == 0 &&
                                                        int2 % a[1] == 0 &&
                                                        int3 % a[2] == 0 &&
                                                        int4 % a[3] == 0 &&
                                                        int5 % a[4] == 0 &&
                                                        int6 % a[5] == 0 &&
                                                        int7 % a[6] == 0 &&
                                                        int8 % a[7] == 0 &&
                                                        int9 % a[8] == 0)
                                                    {
                                                        System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
                                                        System.out.println(int9);
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
  • 相关阅读:
    MySQL 幻读详解
    vue-layer 弹窗z-index问题
    vue-cli 路径不变 改变参数 显示不同组件
    mysql ---- limit使用方式
    mysql ---- 官网的测试数据库
    2020年度总结和2021年目标
    校招(春招实习 + 秋招)总结感想
    Centos8和7的区别(参照redhat)
    centos8 网卡命令(centos7也可用)
    排查linux系统是否被入侵
  • 原文地址:https://www.cnblogs.com/sungong1987/p/11282926.html
Copyright © 2020-2023  润新知