zoukankan      html  css  js  c++  java
  • 三羊献瑞 蓝桥杯

    三羊献瑞
    
    观察下面的加法算式:
    
          祥 瑞 生 辉
      +   三 羊 献 瑞
    -------------------
       三 羊 生 瑞 气
    
    (如果有对齐问题,可以参看【图1.jpg】)
    
    其中,相同的汉字代表相同的数字,不同的汉字代表不同的数字。
    
    请你填写“三羊献瑞”所代表的4位数字(答案唯一),不要填写任何多余内容。

    枚举每一位数字,然后添加判断条件即可。

    public class Main{
        public static void main(String args[]){
            for(int a=1;a<=9;a++){
                for(int b=0;b<=9;b++){
                    for(int c=0;c<=9;c++){
                        for(int d=0;d<=9;d++){
                            for(int e=1;e<=9;e++){
                                for(int f=0;f<=9;f++){
                                    for(int g=0;g<=9;g++){
                                        if(b!=a && (c!=b && c!=a) && (d!=a && d!=b && d!=c) && (e!=a && e!=b && e!=c && e!=d) && (f!=a && f!=b && f!=c && f!=d && f!=e) && (g!=a && g!=b && g!=c && g!=d && g!=e && g!=f)){
                                            int temp=(a*1000+b*100+c*10+d)+(e*1000+f*100+g*10+b);
                                            if(temp>10000){
                                                int a1=temp/10000;
                                                int a2=temp/1000%10;
                                                int a3=temp/100%10;
                                                int a4=temp/10%10;
                                                int a5=temp%10;
                                                if(a1==e && a2==f && a3==c && a4==b && (a5!=a && a5!=b && a5!=c && a5!=d && a5!=e && a5!=f && a5!=g)){
                                                    System.out.println(e+""+f+""+""+g+""+b);
                                                    return;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        
    }

    答案:1085

  • 相关阅读:
    day25:接口类和抽象类
    vue1
    How the weather influences your mood?
    机器学习实验方法与原理
    How human activities damage the environment
    Slow food
    Brief Introduction to Esports
    Massive open online course (MOOC)
    Online learning in higher education
    Tensorflow Dataset API
  • 原文地址:https://www.cnblogs.com/chiweiming/p/10577657.html
Copyright © 2011-2022 走看看