java实现猜算式
题目:猜算式
你一定还记得小学学习过的乘法计算过程,比如:
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实现猜算式的更多相关文章
- Java实现 蓝桥杯 猜算式
猜算式 看下面的算式: □□ x □□ = □□ x □□□ 它表示:两个两位数相乘等于一个两位数乘以一个三位数. 如果没有限定条件,这样的例子很多. 但目前的限定是:这9个方块,表示1~9的9个数字 ...
- C语言 · 猜算式 · 乘法竖式
题目:猜算式 你一定还记得小学学习过的乘法计算过程,比如: 273 x 15 ------ 1365 273 ------ 4095 请你观察如下的乘法算式 *** x *** ------- ...
- C语言 · 猜算式
题目:猜算式 看下面的算式: □□ x □□ = □□ x □□□ 它表示:两个两位数相乘等于一个两位数乘以一个三位数. 如果没有限定条件,这样的例子很多. 但目前的限定是:这9个方块,表示1~9的9 ...
- YTU 2750: 猜算式
2750: 猜算式 时间限制: 1 Sec 内存限制: 128 MB Special Judge 提交: 22 解决: 1 题目描述 看下面的算式: □□ x □□ = □□ x □□□ 它表示 ...
- 算法笔记_220:猜算式(Java)
目录 1 问题描述 2 解决方案 1 问题描述 看下面的算式: □□ x □□ = □□ x □□□ 它表示:两个两位数相乘等于一个两位数乘以一个 三位数. 如果没有限定条件,这样的例子很多. 但 ...
- 初识Java,猜字游戏
import java.util.*; public class caizi{ public static void main(String[] args){ Scanner in=new Scann ...
- Java实现猜字母游戏
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABRQAAAE9CAYAAAB6Cu4FAAAgAElEQVR4nOy995OUR77u2f/H3tjdey ...
- Java实现猜数字,附带提示功能。
很简单的一段代码: package com.changeyd.demo; import java.util.Random;import java.util.Scanner;public class M ...
- java & python猜数字游戏对比
1.java版 package day03; import java.util.Random;import java.util.Scanner; /** * 猜数字游戏 * 随机生成一个1-100之间 ...
随机推荐
- C#枚举高级战术
文章开头先给大家出一道面试题: 在设计某小型项目的数据库(假设用的是 MySQL)时,如果给用户表(User)添加一个字段(Roles)用来存储用户的角色,你会给这个字段设置什么类型?提示:要考虑到角 ...
- iOS事件的响应和传递机制
跟二狗子哥哥交流的时候,他总说我,说的过程太业余.故 好好学习整理一下.努力不那么业余. 一.事件的产生.传递.响应: 1.事件从父控件依次传递到子控件,寻找最合适的子控件View. 2.寻找最合适的 ...
- Spring全家桶之spring boot(三)
spring boot集成mybatis 众所周知,spring与springmvc可以无缝集成,而mybatis不是spring旗下的框架,因此需要进行配置,当然,这里的配置也是非常简单的. 1.首 ...
- Java—线程的生命周期及线程控制方法详解
线程生命周期5种状态 介绍 线程的生命周期经过新建(New).就绪(Runnable).运行(Running).阻塞(Bolocked)和死亡(Dead) 状态转换图 新建(New) 程序使用 ...
- 最简单的git 用法
步骤 在机器上ssh-keygen 然后把id_rsa.pub 复制到csdn 的公钥上去. git clone git@code.csdn.net:aca_jingru/zabbix.git 如果这 ...
- Reflux之Store
Reflux中的Store既是一个listener(既有对action的监听,又有对store的监听)同时又是一个publisher. 一.监听单个action const Reflux = requ ...
- 从零开始实现ASP.NET Core MVC的插件式开发(七) - 近期问题汇总及部分解决方案
标题:从零开始实现ASP.NET Core MVC的插件式开发(七) - 问题汇总及部分解决方案 作者:Lamond Lu 地址:https://www.cnblogs.com/lwqlun/p/12 ...
- C# winform DataGridView 绑定数据的的几种方法
1.用DataSet和DataTable为DataGridView提供数据源 String strConn = "Data Source=.;Initial Catalog=His;User ...
- mysql单记录也能造成的死锁
最近在开发的时候,在mysql Innodb 引擎下,一条记录记录也能引起锁的事件. 场景描述 在项目压测的是,突然发现有类似以下的异常发生: com.mysql.jdbc.exceptions.jd ...
- vue2.0+mint-ui 仿资讯类顶导航内容联动优化
<template><div><div class="navbox"><div class="nav" id=&quo ...