• 古堡算式


    package cn.dlpu.lby;
    
    public class Gubaosuanshi {
    
    	/*
    	福尔摩斯到某古堡探险,看到门上写着一个奇怪的算式:
    	ABCDE * ? = EDCBA
    	他对华生说:“ABCDE应该代表不同的数字,问号也代表某个数字!”
    	华生:“我猜也是!”
    	于是,两人沉默了好久,还是没有算出合适的结果来。
    	请你利用计算机的优势,找到破解的答案。
    	把 ABCDE 所代表的数字写出来。
    	答案写在“解答.txt”中,不要写在这里!
    	 */
    
    	/*方法一:
    	 * public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		int a,b,c,d,e,f;
    		long start = System.currentTimeMillis();
    		for(a = 1;a<=9;a++){
    			for(b=0;b<=9;b++){
    				for(c=0;c<=9;c++){
    					for(d=0;d<=9;d++){
    						for(e=1;e<=9;e++){
    							for(f=1;f<=9;f++){
    								if(a!=b && a!=c && a!=d && a!=e && b!=c && b!=d && b!=e && c!=d && c!=e && d!=e && (10000*a+b*1000+c*100+d*10+e)*f == 10000*e+1000*d+100*c+10*b+a){
    									System.out.println((10000*a+b*1000+c*100+d*10+e)+ "X"+ f  + "="+ (10000*e+1000*d+100*c+10*b+a));
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    		long end = System.currentTimeMillis();
    		System.out.println(end-start);
    	}*/
    	
    	
    	//方法二:
    		public static void main(String[] args){
    			long start = System.currentTimeMillis();
    			for(int i=10000;i<100000;i++){
    				int a = i/10000;
    				int b = i%10000/1000;
    				int c = i%10000%1000/100;
    				int d = i%10000%1000%100/10;
    				int e = i%10;
    				if(a==b||a==c||a==d||a==e||b==c||b==d||b==e||c==d||c==e||d==e){
    					continue;
    				}
    				int y = e*10000+d*1000+c*100+b*10+a;
    				if(y%i==0){
    					System.out.println(i+"*"+y/i+"="+y);
    				}
    			}
    			long end = System.currentTimeMillis();
    			System.out.println(end-start);
    		}
    	}
    
    
    


  • 相关阅读:
    第五周任务以及结对编程
    “爆打”团队阿尔法发布 以及 第四周任务
    第三周内容
    爆打第一次站立会议
    3.23日PSP
    NABCD模型
    个人对结对编程的体会
    Fantacy团队第一次站立会议
    图形设想(简图)
    3月20日随笔
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3144937.html
Copyright © 2020-2023  润新知