今天看到朋友圈里有人发了一张孤独的7的题目,第一反应就是模拟后计算出结果,而女朋友则更爱推理,手算。?
java code:
import java.io.ObjectInputStream.GetField;/** * Project Name:fun * File Name:Main.java * Package Name: * Date:Aug 30, 20152:58:38 PM * Copyright (c) 2015, max_xbw@163.com All Rights Reserved. * *//** * ClassName:Main * Function: TODO ADD FUNCTION. * Reason: TODO ADD REASON. * Date: Aug 30, 2015 2:58:38 PM * * @author xubowen * @version * @since JDK 1.7 * @see */public class Main { static long getnum(long num, int st, int et) { st--; String numstr = String.valueOf(num); String numstrt = numstr.substring(st, et); return Long.valueOf(numstrt); } public static void main(String[] args) { for (int xa = 1; xa <= 9; xa++) { for (int xb = 0; xb <= 9; xb++) { for (int xc = 0; xc <= 9; xc++) { long x = xa * 100 + xb * 10 + xc; for (int ya = 1; ya <= 9; ya++) { int yb = 7; for (int yc = 0; yc <= 9; yc++) { int yd = 0; for (int ye = 0; ye <= 9; ye++) { long y = ya * 10000 + yb * 1000 + yc * 100 + yd * 10 + ye; long z = x * y; // 第一行 // ya*x<1000 long tmp1a = ya * x; if (tmp1a < 1000) { continue; } // 取z的前四位数 long tmp1b = getnum(z, 1, 4); if (tmp1b - tmp1a >= 100) { continue; } long tmp1 = tmp1b - tmp1a; // 第二行 // 3位数 long tmp2a = yb * x; if (tmp2a >= 1000) { continue; } long tmp2b = tmp1 * 10 + getnum(z, 5, 5); long tmp2 = tmp2b - tmp2a; if (tmp2 < 100 || tmp2 > 199) { continue; } // 第三行 long tmp3a = yc * x; if ((tmp3a / 100) != 9 || tmp3a >= 1000) { continue; } long tmp3b = tmp2 * 10 + getnum(z, 6, 6); long tmp3 = tmp3b - tmp3a; if (tmp3 >= 100) { continue; } // 第四行 long tmp4b = ye * x; if (tmp4b < 1000) { continue; } long tmp4a = tmp3 * 100 + getnum(z, 7, 8); if (tmp4a == tmp4b) { System.out.println("x = " + x); System.out.println("y = " + y); System.out.println("z = " + z); System.out.println("结果为 : "); System.out.println(" " + y); System.out.println(" --------"); System.out.println(x+"|"+z); System.out.println(" /"+tmp1a); System.out.println(" ---------"); System.out.println(" " + tmp2b); System.out.println(" " + tmp2a); System.out.println(" ---------"); System.out.println(" " + tmp3b); System.out.println(" " + tmp3a); System.out.println(" ---------"); System.out.println(" " + tmp4b); System.out.println(" " + tmp4a); System.out.println(" ---------"); System.out.println(" 0"); } else { continue; } } } } } } } }}
answer: