题目:猜算式

你一定还记得小学学习过的乘法计算过程,比如:
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. 【clear linux】intel clear linux 电源状态命令

    # 重启系统 $ sudo systemctl reboot # 关闭系统,切断电源 $ sudo systemctl poweroff # CPU停止工作 $ sudo systemctl halt ...

  2. 修改jupyter默认保存文件的目录

    1.打开 Anaconda Prompt输入命令 jupyter notebook --generate-config 2.可以看到生成了目录及jupyter notebook的配置文件,打开该文件. ...

  3. sonar 安装,centos7配置优化

    /etc/sysctl.conf /etc/systemd/system.conf /etc/security/limits.conf /proc/sys/fs/file-max /etc/secur ...

  4. protus中出现invalid internal memory size ==NULL

    点击8086芯片,更改internal memory size的大小为0x10000

  5. ES6常见面试题

    1.es5和es6的区别,说一下你所知道的es6 ECMAScript5,即ES5,是ECMAScript的第五次修订,于2009年完成标准化 ECMAScript6,即ES6,是ECMAScript ...

  6. linux常用命令---系统辅助命令

    系统辅助命令

  7. 在php文件中xml格式

    本人是小白,有错误的地方请指正,勿喷! 在写一个调查问卷的过程中用到了xml文件,如想要了解,可以通过以下链接简单学习:http://www.w3school.com.cn/xml/ 所用工具:php ...

  8. oracle 查询表及字段结构

    select --*tcl.column_name,cc.comments col_comments,data_type,case data_type when 'NUMBER' then '('|| ...

  9. Git基本操作命令合集

    平时自己敲敲代码,使用Git命令也渐渐多了起来.使用起来的确很方便,今天来分享下Git基本概念和本地代码提交到github上的过程,很简单的,多操作几次就会了. Git定义 Git 是一个开源的分布式 ...

  10. Fabric CA的部署与使用

    Fabric CA是Hyperledger Fbric的证书认证中心,提供以下功能:用户信息的登记与注册,数字证书的颁发与管理. 前言 之前使用CA服务一直是在docker容器中运行下载好的CA镜像, ...