蓝桥杯第七届C组第六题

题目:

凑算式

在这里插入图片描述

这个算式中AI代表19的数字,不同的字母代表不同的数字。

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

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

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

思路:这道题用暴力就可以了

代码:

public class Main {
	public static void main(String[] args) {
		int w=0;
		for (double a =1; a <10; a++) {
			for (double b = 1; b <10; b++) {
				for (double c = 1; c <10; c++) {
					for (double d = 1; d <10; d++) {
						for (double e = 1; e <10; e++) {
							for (double f = 1; f < 10; f++) {
								for (double g = 1; g < 10; g++) {
									for (double h = 1; h <10; h++) {
										for (double 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&
						    h!=i&
							a+(b/c)+((d*100+e*10+f)/(g*100+h*10+i))==10){
								w++;
								
							                }	
										}
									}
								}
							}
						}
					}	
				}			
			}
		}
		System.out.println(w);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_43394463/article/details/87879740