火柴棍等式枚举一
package com.jkxy.enumeration;
public class MatchStick {
public static void main(String[] args) {
int a,b,c,sum=0,m=18;
for(a=0;a<=1111;a++){
for(b=0;b<=1111;b++){
c=a+b;
if (num(a)+num(b)+num(c)==m-4){
System.out.println("a:"+a+"b:"+b+"c"+c);
sum++;
}
}
}
System.out.println("sum"+sum);
}
public static int num(int k){
int total=0;
int[] f={6,2,5,5,4,5,6,3,7,6};
while(k/10!=0){
total+=f[k%10];
k=k/10;
}
total+=f[k];
return total;
}
}
/*从main开始写,火柴棍数,开始枚举(双循环第一个数a,第二个数b)循环体算第三个数c的值,以及等式数sum
如果a.b.c的总棍数为m-4,则输出a,b,c。循环体外输出满足条件的总等式数*/
暴力奥数枚举二:
package com.jkxy.enumeration;
public class Enum {
public static void main(String[] args) {
int a, b, c, d, e, f, g, h, i,total = 0;
for (a = 1; a <=9; a++)
for (b = 1; b<=9; b++)
for (c = 1; c <= 9; c++)
for (d = 1; d <= 9; d++)
for (e = 1; e <= 9; e++)
for (f = 1; f <= 9; f++)
for (g = 1; g <= 9; g++)
for (h = 1; h <= 9; h++)
for (i = 1; i <= 9; i++) {
if (a != b && a != c && a != d&& a != e && a != f&& a != g && a != h&& a != i
&& b != c && b != d&& b != e && b != f&& b != g && b != h&& b != i
&& c != d&& c != e && c != f&& c != g && c != h&& c != i
&& d != e && d != f&& d != g && d != h&& d != i
&& e != f&& e != g && e != h&& e != i
&& f != g && f != h&& f != i
&& g != h&& g != i
&& h != i
&&(a*100+b*10+c+d*100+e*10+f==g*100+h*10+i)){
total++;
System.out.print(a);
System.out.print(b);
System.out.print(c);
System.out.print(d);
System.out.print(e);
System.out.print(f);
System.out.print(g);
System.out.print(h);
System.out.print(i);
System.out.print("/");
}
}
System.out.println("tatal"+total/2);
}
}
一到九填入XXX+XXX=XXX;
三:总结起来无非:多重循环枚举,循环内判断并输出。