蓝桥杯 第七届省赛试题 凑算式

来源:互联网 发布:getopt python 编辑:程序博客网 时间:2024/05/07 15:57
凑算式

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



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

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

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

注意:你提交应该是个整数,不要填写任何多余的内容或说明性文字。
package com.diqijie.shengsai;import java.util.HashSet;/** * @author leibaobao * 凑算式 * 解:前几题不要多想,暴力一点。但是Java能不用大数不要去用大数 * 麻烦,慢。这题通分加for循环不就OK了吗 */public class _3 {public static void main(String[] args) {// TODO Auto-generated method stubint count = 0;for(int a = 1; a < 10; a++)for(int b = 1; b < 10; b++)for(int c = 1; c < 10; c++)for(int d = 1; d < 10; d++)for(int e = 1; e < 10; e++)for(int f = 1; f < 10; f++)for(int g = 1; g < 10; g++)for(int h = 1; h < 10; h++)for(int i = 1; i < 10; 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&&i!=h){int temp_1 = b*(g*100 +h*10 +i);int temp_2 = c*(d*100+e*10+f);int temp_3 = c*(g*100 +h*10 +i);if((temp_1+temp_2)%temp_3 == 0)if(a + (temp_1+temp_2)/temp_3 == 10){count++;}}}System.out.println(count);}}

0 0
原创粉丝点击