三羊献瑞

 

 

 

其中,相同的汉字代表相同的数字,不同的汉字代表不同的数字。

请你填写“三羊献瑞”所代表的4位数字(答案唯一),不要填写任何多余内容。

思路:由题意可知‘三’必定为1  在将其他汉字赋值枚举 注意不相等

package com.smh.year2015;

/**
 * @version 1.0
 * @auther 孙沐华
 */
public class test03 {
    public static void main(String[] args) {
        int a1;
        int a2;
        int sum;
        for (int a = 0; a <10 ; a++) {
            for (int b = 0; b < 10; b++) {
                for (int c = 0; c <10 ; c++) {
                    for (int d = 0; d <10 ; d++) {
                        for (int f = 0; f <10 ; f++) {
                            for (int g = 0; g <10 ; g++) {
                                for (int h = 0; h < 10; h++) {
                                    if (a!=b && a!=c && a!=d && a!=f && a!=g && a!=h
                                            && b!=c && b!=d && b!=f && b!= g &&b!=h
                                            && c!=d && c!=f && c!= g && c!=h
                                            && d!=f && d!=g &&d!=h
                                            && f!=g && f!=h
                                            && g!=h
                                        &&a!=1&&b!=1&&c!=1&&d!=1&&f!=1&&g!=1&&h!=1){
                                        a1=f*1000+100*c+10*b+g;
                                        a2=1000+a*100+10*h+c;
                                        sum=10000+1000*a+100*b+10*c+d;
                                        if (sum==a1+a2){
                                            System.out.println(1000+100*a+10*h+c);
                                        }
                                    }

                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

  

posted @ 2023-03-08 20:08  星星··  阅读(17)  评论(0)    收藏  举报