package xiaosuanfa;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Cacul24 {
public static Set<String> set;
public static void main(String[] args) {
double [] nums= {11,6,13,13};//在此输入四个数字
set=new HashSet<String>();
cacul(nums[0],nums[1],nums[2],nums[3],"");
Iterator<String> iterator=set.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
}
private static void cacul(double a, double b, double c, double d,String str) {
if(b==0){
if(a>23.999&&a<24.001){
if(str.contains(",")){
str=str.replace(",", "-");
}
set.add(str);
}
}else if(c==0){
String str2=str;
for(int i=0;i<6;i++){
if(str.contains(",")){
String strs []= str2.split(",");
str=calSign(strs[0],i,strs[1]);
}else{
str=calSign((int)a+"",i,str2);
}
cacul(cacul(a,b,i),0,0,0,str);
str=str2;
}
}else if(d==0){
String str2=str;
for(int i=0;i<6;i++){
str=str2+","+calSign((int)a+"",i,""+(int)b);
cacul(c,cacul(a,b,i),0,0,str);
str=str2;
}
for(int i=0;i<6;i++){
str=calSign((int)a+"",i,str2);
cacul(b,cacul(a,c,i),0,0,str);
str=str2;
}
for(int i=0;i<6;i++){
str=calSign((int)b+"",i,str2);
cacul(a,cacul(b,c,i),0,0,str);
str=str2;
}
}else{
for(int i=0;i<6;i++){
str=calSign((int)a+"",i,""+(int)b);
cacul(c,d,cacul(a,b,i),0,str);
}
for(int i=0;i<6;i++){
str=calSign((int)a+"",i,""+(int)c);
cacul(b,d,cacul(a,c,i),0,str);
}
for(int i=0;i<6;i++){
str=calSign((int)b+"",i,""+(int)c);
cacul(a,d,cacul(b,c,i),0,str);
}for(int i=0;i<6;i++){
str=calSign((int)a+"",i,""+(int)d);
cacul(b,c,cacul(a,d,i),0,str);
}
for(int i=0;i<6;i++){
str=calSign((int)b+"",i,""+(int)d);
cacul(a,c,cacul(b,d,i),0,str);
}
for(int i=0;i<6;i++){
str=calSign((int)c+"",i,""+(int)d);
cacul(a,b,cacul(c,d,i),0,str);
}
}
}
private static String calSign( String a, int type, String b) {
switch(type){
case 0 :return "("+a+"+"+b+")";
case 1 :return "("+a+"-"+b+")";
case 2 :return a+"*"+b;
case 3 :return a+"/"+b;
case 4 :return "("+b+"-"+a+")";
case 5 :return b+"/"+a;
}
return null;
}
private static double cacul(double a, double b,int type) {
switch(type){
case 0 :return a+b;
case 1 :return a-b;
case 2 :return a*b;
case 3 :return a/b;
case 4 :return b-a;
case 5 :return b/a;
}
return 0;
}
}