import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String input[] = str.split(" ");
Map<Integer, Integer> map = new HashMap<>();
for(int i=0;i<input.length;i++){
int curr = Integer.parseInt(input[i]);
if(map.containsKey(curr))
map.put(curr,map.get(curr)+1);
else map.put(curr,1);
}
for(int i=1;i<10;i++){
if(map.containsKey(i)&&map.get(i)<4){
map.put(i,map.get(i)+1);
}
else if(!map.containsKey(i)){
map.put(i,1);
}
else continue;
List<Map<Integer, Integer>> list = removeJiang(map);
for(Map<Integer, Integer> m : list){
if(is(m))
System.out.print(i+" ");
}
map.put(i,map.get(i)-1);
}
}
public static List<Map<Integer, Integer>> removeJiang(Map<Integer, Integer> map){
List<Map<Integer, Integer>> list = new ArrayList<>();
for(int i:map.keySet()){
if(map.containsKey(i)&&map.get(i)>=2){
Map<Integer, Integer> m = new HashMap<>(map);
m.put(i,m.get(i)-2);
list.add(m);
}
}
return list;
}
public static boolean is(Map<Integer, Integer> map){
if(map==null) return false;
for (int i=1;i<10;i++){
int start = map.getOrDefault(i,0);
if(start == 0) continue;
if(start<3&&map.getOrDefault(i+1,0)>0&&map.getOrDefault(i+2,0)>0){
map.put(i,start-1);
map.put(i+1, map.get(i+1)-1);
map.put(i+2, map.get(i+2)-1);
i--;
}
else if(start>=3){
map.put(i--,start-3);
}
else return false;
}
return true;
}
}
雀神启动!
最新推荐文章于 2024-01-12 10:48:11 发布