zoukankan      html  css  js  c++  java
  • 马虎的算式


    本人解法 比较笨

    public class Main {
    	// 测试代码
    	public static void main(String[] args) {
    		// 定义一个字符串用于连接五个数字
    		int sum = 0;
    		for (int i = 10; i <= 99; i++) {
    			for (int x = 100; x <= 999; x++) {
    				String str = "";
    				Boolean flag = true;
    				str = str + i;
    				str = str + x;
    				// 用于记录每个字母出现的次数
    				int[] arr = new int[10];
    				for (int y = 0; y < 5; y++) {
    					String s = String.valueOf(str.charAt(y));
    					int value = Integer.parseInt(s);
    					arr[value]++;
    					if (arr[value] == 2 ||value ==0) {
    						flag = false;
    						break;
    					}
    				}
    				if (flag == true) {
    					String s1 = "";
    					String s2 = "";
    					s1 = s1 + String.valueOf(str.charAt(0));
    					s1 = s1 + String.valueOf(str.charAt(3));
    					s1 = s1 + String.valueOf(str.charAt(1));
    					s2 = s2 + String.valueOf(str.charAt(2));
    					s2 = s2 + String.valueOf(str.charAt(4));
    					int s3 = Integer.parseInt(s1);
    					int s4 = Integer.parseInt(s2);
    					if ((s3 * s4) == (i * x)) {
    						sum++;
    					}
    				}
    			}
    		}
    		System.out.println(sum);
    	}
    }
    

    另一种解法

    public static void main(String[] args) {
    		int sum = 0;
    		for (int a = 1; a <= 9; a++) {
    			for (int b = 1; b <= 9; b++) {
    				if (b != a) {
    					for (int c = 1; c <= 9; c++) {
    						if (c != b && c != a) {
    							for (int d = 1; d <= 9; d++) {
    								if (d != c && d != b && d != a) {
    									for (int e = 1; e <= 9; e++) {
    										if (e != d && e != c && e != b && e != a) {
    											if ((a * 10 + b) * (c * 100 + d * 10 + e) == (a * 100 + d * 10 + b)* (c * 10 + e)) {
    												sum++;
    												System.out.println(sum);
    											}
    										}
    									}
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    }
    
  • 相关阅读:
    前端之HTML
    面向对象编程思想
    【统计】Causal Inference
    Python 最常见的 170 道面试题全解析:2019 版
    面试mysql表设计要注意啥
    数据分析资料汇总
    【crunch bang】论坛tint2配置讨论贴
    【crunch bang】增加壁纸图片文件
    【linux】xx is not in the sudoers file 解决办法
    【crunch bang】安装firefox,删除iceweasel
  • 原文地址:https://www.cnblogs.com/cznczai/p/11150622.html
Copyright © 2011-2022 走看看