三羊献瑞

题目描述

观察下面的加法算式:

  祥 瑞 生 辉
  • 三 羊 献 瑞

三 羊 生 瑞 气

(如果有对齐问题,可以参看【图1.jpg】)

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

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

结果:1085

import java.util.Arrays;

public class Main {

    public static boolean judge(int[] A) {
int[] tempA = new int[A.length];
for(int i = 0;i < A.length;i++)
tempA[i] = A[i];
Arrays.sort(tempA); //对tempA元素进行从小到大排序
for(int i = 1;i < tempA.length;i++) {
if(tempA[i - 1] == tempA[i])
return false;
}
return true; } public static boolean judge1(int[] A, int[] B) {
int[] temp = new int[A.length + B.length - 1];
int i = 0;
for(;i < A.length;i++)
temp[i] = A[i];
for(;i < temp.length;i++)
temp[i] = B[i - A.length];
Arrays.sort(temp);
for(i = 1;i < temp.length;i++) {
if(temp[i - 1] == temp[i])
return false;
}
return true;
} public static void main(String[] args) {
for(int i = 1000;i <= 9999;i++) {
int[] A = new int[4];
A[0] = i / 1000;
A[1] = i / 100 % 10;
A[2] = i / 10 % 10;
A[3] = i % 10;
if(judge(A) == false)
continue;
for(int j = 1000;j <= 9999;j++) {
int[] B = new int[4];
B[0] = j / 1000;
B[1] = j / 100 % 10;
B[2] = j / 10 % 10;
B[3] = j % 10;
if(judge(B) == false)
continue;
if(B[3] != A[1])
continue;
if(judge1(A, B) == false)
continue;
int temp = i + j;
if(temp < 9999 || temp > 99999)
continue;
int[] C = new int[5];
C[0] = temp / 10000;
C[1] = temp / 1000 % 10;
C[2] = temp / 100 % 10;
C[3] = temp / 10 % 10;
C[4] = temp % 10;
if(C[0] == B[0] && C[1] == B[1] && C[2] == A[2] && C[3] == A[1]) {
if(C[4] != A[0] && C[4] != A[1] && C[4] != A[2] && C[4] != A[3]) {
if(C[4] != B[0] && C[4] != B[1] && C[4] != B[2] && C[4] != B[3])
System.out.println("i = "+i+", j = "+j+", temp = "+temp);
}
}
}
}
}
}

最新文章

  1. C#小方法PadLeft 和 PadRight
  2. #研发中间件介绍#定时任务调度与管理JobCenter
  3. xss跨站实例总结
  4. 设置TextView下划线并响应点击事件(SpannableString)
  5. php删除html标签的三种解决方法
  6. json,serialze之格式
  7. spring--处理器拦截器详解——跟着开涛学SpringMVC
  8. 一个很cool的C#的高性能数学库
  9. Java高精度学习第二弹——求N!
  10. 转:TestLink1.9.3测试用例:Excel转换XML工具&lt;二&gt;实现代码
  11. UILocalNotification
  12. Windows平台内核级文件访问
  13. 让Linux开机运行命令
  14. 用windows性能监视器监控sqlserver的常见指标
  15. JPA 系列教程11-复合主键-2个@Id
  16. LeetCode 40. Combination Sum II (组合的和之二)
  17. window下eclipse4.5+hadoop2.6.1开发环境配置
  18. 构建FTP服务
  19. (八)lambda、列表生成式、字典转list排序
  20. 曙光服务器挂载EMC存储

热门文章

  1. 前端:参数传错了,spring-boot:那错误信息我给你显示的友好点儿
  2. hadoop与spark的处理技巧(一)Top N处理技巧
  3. python装饰器在接口自动化测试中的应用
  4. Docker的安装(Linux)
  5. Objective-C中的加号与减号
  6. 还不会K8S吗?先从kubeadm开始吧
  7. SSE系列内置函数中的shuffle函数
  8. 掌握了Docker Layer Caching才敢自称精通Dockerfile
  9. channelartlist标签的使用
  10. vue中使用jsx