题目:猜算式

你一定还记得小学学习过的乘法计算过程,比如:
x 15
------
273
------ 请你观察如下的乘法算式 ***
x ***
--------
***
***
***
--------
***** 星号代表某位数字,注意这些星号中,
0~9中的每个数字都恰好用了2次。
(如因字体而产生对齐问题,请参看图p1.jpg) 请写出这个式子最终计算的结果,就是那个5位数是多少? 注意:只需要填写一个整数,不要填写任何多余的内容。比如说明文字。
import java.util.ArrayList;
import java.util.Collections; public class Main { public boolean judge(int temp1, int temp2, int temp3, int temp4, int temp5, int temp6) {
ArrayList<Integer> list = new ArrayList<Integer>();
while(temp1 > 0) {
list.add(temp1 % 10);
temp1 = temp1 / 10;
}
while(temp2 > 0) {
list.add(temp2 % 10);
temp2 = temp2 / 10;
}
while(temp3 > 0) {
list.add(temp3 % 10);
temp3 = temp3 / 10;
}
while(temp4 > 0) {
list.add(temp4 % 10);
temp4 = temp4 / 10;
}
while(temp5 > 0) {
list.add(temp5 % 10);
temp5 = temp5 / 10;
}
while(temp6 > 0) {
list.add(temp6 % 10);
temp6 = temp6 / 10;
}
Collections.sort(list);
if(list.size() == 20) {
int j = 0;
for(int i = 0;i < 20;i = i + 2, j++) {
if(list.get(i) == j && list.get(i + 1) == j)
continue;
else
return false;
}
if(j == 10)
return true;
}
return false;
} public boolean judge1(int n) {
if(n >= 1000 || n < 100)
return false;
return true;
} public void printResult() {
for(int i = 100;i <= 999;i++) {
int temp1 = i;
for(int j = 100;j <= 999;j++) {
int temp2 = j;
int temp3 = temp2 % 10 * temp1;
int temp4 = temp2 / 10 % 10 * temp1;
int temp5 = temp2 / 100 * temp1;
int temp6 = temp2 * temp1;
if(judge1(temp3) && judge1(temp4) && judge1(temp5) && temp6 > 9999 && temp6 < 100000) {
if(judge(temp1, temp2, temp3, temp4, temp5, temp6)) {
System.out.println("temp1 = "+temp1+", temp2 = "+temp2+", temp6 = "+temp6);
}
} else {
continue;
}
}
}
} public static void main(String[] args) {
Main test = new Main();
test.printResult();
}
}

java实现猜算式的更多相关文章

  1. Java实现 蓝桥杯 猜算式

    猜算式 看下面的算式: □□ x □□ = □□ x □□□ 它表示:两个两位数相乘等于一个两位数乘以一个三位数. 如果没有限定条件,这样的例子很多. 但目前的限定是:这9个方块,表示1~9的9个数字 ...

  2. C语言 · 猜算式 · 乘法竖式

    题目:猜算式 你一定还记得小学学习过的乘法计算过程,比如: 273 x   15 ------ 1365 273 ------ 4095 请你观察如下的乘法算式 *** x   *** ------- ...

  3. C语言 · 猜算式

    题目:猜算式 看下面的算式: □□ x □□ = □□ x □□□ 它表示:两个两位数相乘等于一个两位数乘以一个三位数. 如果没有限定条件,这样的例子很多. 但目前的限定是:这9个方块,表示1~9的9 ...

  4. YTU 2750: 猜算式

    2750: 猜算式 时间限制: 1 Sec  内存限制: 128 MB  Special Judge 提交: 22  解决: 1 题目描述 看下面的算式: □□ x □□ = □□ x □□□ 它表示 ...

  5. 算法笔记_220:猜算式(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 看下面的算式: □□ x □□ = □□ x □□□ 它表示:两个两位数相乘等于一个两位数乘以一个 三位数. 如果没有限定条件,这样的例子很多. 但 ...

  6. 初识Java,猜字游戏

    import java.util.*; public class caizi{ public static void main(String[] args){ Scanner in=new Scann ...

  7. Java实现猜字母游戏

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABRQAAAE9CAYAAAB6Cu4FAAAgAElEQVR4nOy995OUR77u2f/H3tjdey ...

  8. Java实现猜数字,附带提示功能。

    很简单的一段代码: package com.changeyd.demo; import java.util.Random;import java.util.Scanner;public class M ...

  9. java & python猜数字游戏对比

    1.java版 package day03; import java.util.Random;import java.util.Scanner; /** * 猜数字游戏 * 随机生成一个1-100之间 ...

随机推荐

  1. springBoot整合Mybatis,Junit

    笔记源码:https://gitee.com/ytfs-dtx/SpringBoot 整合Mybatis SpringBoot的版本:2.2.5.RELEASE Mybatis版本:mybatis-s ...

  2. xilinx VDMA IP核使用

    VDMA实用配置说明 VDMA是通过AXI Stream协议对视频数据在PS与PL端进行搬运,开发者无需关注AXI Stream协议,在BlockDesign设计中只需要把相应信号进行连接即可. VD ...

  3. linux centos7 和 windows下 部署 .net core 2.0 web应用

    centos7 下部署asp.net core 2.0应用 安装CentOS7 配置网络[可选] 安装.Net core2.0 创建测试Asp.net Core应用程序 正式部署项目 安装VMware ...

  4. PHP正则表达式语法汇总

    首先,让我们看看两个特别的字符:'^' 和 ‘$' 他们是分别用来匹配字符串的开始和结束,一下分别举例说明"^The": 匹配以 "The"开头的字符串;&qu ...

  5. c#与js客户端之间相互传值

    RegisterStartupScript(key, script) RegisterClientScriptBlock(key, script) 第一个参数 key 是插入的客户端脚本的唯一标识符. ...

  6. sublime text 3 关联鼠标右击

    比如有网上有如下方法 https://my.oschina.net/adairs/blog/466777 , 其实一个更简单的方法是运行sublime setup.exe , 直接会有相关提示,下一步 ...

  7. HashMap基本介绍

    1.HashMap简介(本文是按照JDK1.8进行解析) HashMap位于JDK自带jar包rt.jar的java.util目录下. HashMap是一个散列表,存储的内容是键值对<key,v ...

  8. 枚举 转化为可行性判定问题 网络流 poj3189

    Steady Cow Assignment Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6914   Accepted: ...

  9. JAVA设计模式之原型模式(prototype)

    原型模式: 原型模式又叫克隆模式 Java自带克隆模式 实现克隆模式必须实现Cloneable 接口,如果不实现会发生java.lang.CloneNotSupportedException异常 当某 ...

  10. Angular SPA基于Ocelot API网关与IdentityServer4的身份认证与授权(三)

    在前面两篇文章中,我介绍了基于IdentityServer4的一个Identity Service的实现,并且实现了一个Weather API和基于Ocelot的API网关,然后实现了通过Ocelot ...