日期:2014-05-20 浏览次数:21014 次
public class MakeEffort { public static void main(String[] args) { int a, b, c, d, e, f; for (a = 1; a <= 9; ++a) { for (b = 2; b <= 8; b += 2) { if (a != b) { for (c = 1; c <= 9; ++c) { if (c != a && c != b) { for (d = 2; d <= 8; d += 2) { if (d != a && d != b && d != c) { for (e = 1; e <= 9; ++e) { if (e != a && e != b && e != c && e != d) { for (f = 1; f <= 9; ++f) { if ((2*(a*100000 + b*10000 + c*1000 + d*100 + e*10 + f) == (c*100000 + d*10000 + e*1000 + f*100 + a*10 + b)) && (2*(c*100000 + d*10000 + e*1000 + f*100 + a*10 + b)) == (e*100000 + f*10000 + a*1000 + b*100 + c*10 + d)) { System.out.println("a = " + a + ", b = " + b + ", c = " + c + ", d = " + d + ", e = " + e + ", f = " + f); } } } } } } } } } } } } }
------解决方案--------------------
ABCDEF 是142857
import java.util.Arrays; /** * Created by IntelliJ IDEA. * User: Administrator * Date: 2011-10-1 * Time: 21:32:15 * To change this template use File | Settings | File Templates. */ public class PuzzleDemo { /** * * @param num * @return */ public static char[] parse(int num){ char[] result=new char[6]; String s=Integer.toString(num); for(int i=0;i<6;i++){ result[i]=s.charAt(i); } return result; } public static void main(String[] args) { // char[] char1=parse(123456); // char[] char2=new char[6]; // char[] char3=new char[6]; // // for(int j=0;j<6;j++){ // int aa=(j+2)%6; // char2[j]=char1[aa]; // } // for(int j=0;j<6;j++){ // int aa=(j+4)%6; // char3[j]=char1[aa]; // } // String s1=new String(char1); // String s2=new String(char2); // String s3=new String(char3); // System.out.println(s1); // System.out.println(s2); // System.out.println(s3); // System.out.println("解析:"+ Arrays.toString(char1)); // System.out.println("解析:"+ Arrays.toString(char2)); // System.out.println("解析:"+ Arrays.toString(char3)); for(int i=100000;i<999999;i++){ char[] char1=parse(i); char[] char2=new char[6]; for(int j=0;j<6;j++){ int aa=(j+2)%6; char2[j]=char1[aa]; } char[] char3=new char[6]; for(int j=0;j<6;j++){ int aa=(j+4)%6; char3[j]=char1[aa]; } String s1=new String(char1); String s2=new String(char2); String s3=new String(char3); int i2=Integer.parseInt(s2); int i3=Integer.parseInt(s3); if(i*2==i2&&i2*2==i3){ //这里还需要检查6位数字是否重复 ,因为不写也只有一个结果,没写 // for(){ // // } System.out.println(i); } } } }