标签:style class blog c code java
package Pro0519; import java.util.Arrays; public class pro0519 { public static void main(String[] args) { String[] ar_str1, ar_str2; int sum = 0; int from; int to; int i_val; int count = 0; // 双重循环穷举 for (int i = 10; i < 100; i++) { // j=i+1避免重复 from = Math.max(1000 / i, i + 1); to = Math.min(10000 / i, 100); for (int j = from; j < to; j++) { i_val = i * j; // 下面的这个代码,我个人并不知道为什么,汗颜 if (i_val % 100 == 0 || (i_val - i - j) % 9 != 0) { continue; } count++; ar_str1 = String.valueOf(i_val).split(""); ar_str2 = (String.valueOf(i) + String.valueOf(j)).split(""); Arrays.sort(ar_str1); Arrays.sort(ar_str2); if (Arrays.equals(ar_str1, ar_str2)) {// 排序后比较,为真则找到一组 sum++; System.out.println("第" + sum + "组: " + i + "*" + j + "=" + i_val); } } } System.out.println("共找到" + sum + "组吸血鬼数"); System.out.println(count); } }
标签:style class blog c code java
原文地址:http://www.cnblogs.com/tech-bird/p/3736704.html