zoukankan      html  css  js  c++  java
  • 蓝桥杯-凑算式-java

    /* (程序头部注释开始)

    * 程序的版权和版本声明部分

    * Copyright (c) 2016, 广州科技贸易职业学院信息工程系学生 

    * All rights reserved.

    * 文件名称: 蓝桥杯赛题                           

    * 作    者:   彭俊豪               

    * 完成日期:   2016   年 04月 01日

    * 版 本 号:      001   

    * 对任务及求解方法的描述部分

    * 问题描述:

           B       DEF
    A + --- + ------- = 10
           C       GHI

    (如果显示有问题,可以参见【图1.jpg】)


    这个算式中A~I代表1~9的数字,不同的字母代表不同的数字。

    比如:
    6+8/3+952/714 就是一种解法,
    5+3/1+972/486 是另一种解法。

    这个算式一共有多少种解法?

    注意:你提交应该是个整数,不要填写任何多余的内容或说明性文字。

     * 程序输出:  你提交应该是个整数,不要填写任何多余的内容或说明性文字。

    * 程序头部的注释结束

    */

    上代码:

    public class Main {

    public static void main(String[] args) {
      int count=0;
      for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
          for(int k=1;k<10;k++){
            for(int l=1;l<10;l++){
              for(int m=1;m<10;m++){
                for(int n=1;n<10;n++){
                  for(int o=1;o<10;o++){
                    for(int p=1;p<10;p++){
                      for(int q=1;q<10;q++){
                        int arr[] = new int[]{i,j,k,l,m,n,o,p,q};
                          if(panDuan(arr)==1 ){
                            if (j*(o*100+p*10+q)+k*(l*100+m*10+n)==k*(o*100+p*10+q)*(10-i)) {
                              System.out.println(i+"+"+j+"/"+k+"+"+(l*100+m*10+n)+"/"+(o*100+p*10+q)+"=10");
                              count++;
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
        System.out.println(count);
      }

      public static int panDuan(int[] arr){
        for(int i=0;i<arr.length-1;i++){
          for(int j=i+1;j<arr.length;j++){
            if(arr[j]==arr[i]){
              return 0;
            }
          }
        }
        return 1;
      }

    }

  • 相关阅读:
    转:git上传本地项目到github
    转:git常用操作
    idea常用快捷键
    转:spring中InitailizingBean接口的简单理解
    resulting in duplicate entry '1' for key 'primary'
    Uncaught SyntaxError: Unexpected identifier
    This application has no explicit mapping for /error, so you are seeing this as a fallback.
    启动web项目报错:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone.
    解决 "Could not autowire. No beans of 'SationMapper' type found" 的问题
    javascript 判断系统设备
  • 原文地址:https://www.cnblogs.com/pengjunhao/p/6674427.html
Copyright © 2011-2022 走看看