package test8; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class test1 { public static boolean SNum(int num){ Set<Integer> set = new HashSet<>(); set.clear(); while(num > 0){ set.add(num % 10); num /= 10; } return set.size() == 5?true:false; } public static boolean SetNum(int i,int j){ Set<Integer> w = new HashSet<>(); Set<Integer> set = new HashSet<>(); int a = i; int b = j; set.clear(); while(i > 0){ set.add(i % 10); i /= 10; } if(set.size() != 4){ return false; } while(j > 0){ w.add(j % 10); j /= 10; } if(w.size() != 4){ return false; } ArrayList<Integer> list = new ArrayList<>(w); for(int k = 0;k < list.size();k++){ set.add(list.get(k)); } return set.size() == 7 && (a / 100 % 10 == b % 10)?true:false; } public static int SumNum(int i,int j){ String s1 = i+""; String s2 = j+""; String word = s2.charAt(0) + ""+ s2.charAt(1) + "" + s1.charAt(2)+""+s2.charAt(3)+""; return Integer.parseInt(word); } public static void main(String[] args){ for(int i = 1000;i <= 9999;i++){ for(int j = 1000;j <= 9999;j++){ if((i+j) > 10000 && (i+j) /10 == SumNum(i,j) && SetNum(i,j) && SNum(i+j)){ System.out.println(i); System.out.println(j); System.out.println(i+j); return; } } } } }
题目其实很简单,但是限制条件多导致出错了调试了好久。。。