`

一道小学奥数题的Java编程实现

阅读更多
2012华杯小中年级初赛试题的第一题解析
原题如下

程序源码


import java.util.HashSet;
import java.util.Set;

public class Sum {


	static private boolean isCollect(int a, int b, int c, int d, int e, int f) {
		int sum = a * 100 + b * 10 + c + d * 100 + e * 10 + f;

		if (sum > 1000)
			return false;

		int h = sum / 100;
		int j = (sum - h * 100) / 10;
		int k = sum % 10;
		Set s = new HashSet();
		s.add(a);
		s.add(b);
		s.add(c);
		s.add(d);
		s.add(e);
		s.add(f);
		s.add(h);
		s.add(j);
		s.add(k);

		boolean res = s.size() == 9 && !s.contains(0);
		if (res) {
			int all = h + j + k;
			System.out.println(sum + ":" + all);
		}
		return res;

	}

	static int dig[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

	public static void main(String[] args) {
		int a, b, c, d, e, f, g, h, j, k;
		int total = 0;
		int count = 0;
		for (int i1 = 0; i1 < dig.length; i1++) {
			a = dig[i1];
			for (int i2 = 0; i2 < dig.length; i2++) {
				if (i1 == i2) {
					continue;
				}
				b = dig[i2];

				for (int i3 = 0; i3 < dig.length; i3++) {
					if (i3 == i2 || i3 == i1) {
						continue;
					}
					c = dig[i3];

					for (int i4 = 0; i4 < dig.length; i4++) {
						if (i4 == i1 || i4 == i2 || i4 == i3)
							continue;

						d = dig[i4];
						for (int i5 = 0; i5 < dig.length; i5++) {
							if (i5 == i1 || i5 == i2 || i5 == i3 || i5 == i4) {
								continue;
							}
							e = dig[i5];

							for (int i6 = 0; i6 < dig.length; i6++) {
								if (i6 == i1 || i6 == i2 || i6 == i3
										|| i6 == i4 || i6 == i5) {
									continue;
								}
								f = dig[i6];
								total++;
								if (isCollect(a, b, c, d, e, f)) {
									count++;
									System.out.println("answer is:" + a + b + c
											+ "," + d + e + f);
								}

							}
						}
					}

				}
			}
		}

		System.out.println("total check:" + total);
		System.out.println("answer count:" + count);

	}
}


答案是18

代码运行后输出如下
783:18
answer is:124,659
864:18
answer is:125,739
486:18
answer is:127,359
495:18
answer is:127,368
495:18
answer is:128,367
567:18
answer is:128,439
486:18
answer is:129,357
567:18
answer is:129,438
783:18
answer is:129,654
864:18
answer is:129,735
792:18
answer is:134,658
864:18
answer is:135,729
567:18
answer is:138,429
792:18
answer is:138,654
567:18
answer is:139,428
864:18
answer is:139,725
738:18
answer is:142,596
837:18
answer is:142,695
729:18
answer is:143,586
837:18
answer is:145,692
729:18
answer is:146,583
738:18
answer is:146,592
639:18
answer is:152,487
936:18
answer is:152,784
783:18
answer is:154,629
792:18
answer is:154,638
936:18
answer is:154,782
486:18
answer is:157,329
639:18
answer is:157,482
792:18
answer is:158,634
486:18
answer is:159,327
783:18
answer is:159,624
549:18
answer is:162,387
945:18
answer is:162,783
945:18
answer is:163,782
495:18
answer is:167,328
549:18
answer is:167,382
495:18
answer is:168,327
459:18
answer is:173,286
468:18
answer is:173,295
468:18
answer is:175,293
459:18
answer is:176,283
549:18
answer is:182,367
576:18
answer is:182,394
639:18
answer is:182,457
675:18
answer is:182,493
936:18
answer is:182,754
945:18
answer is:182,763
459:18
answer is:183,276
675:18
answer is:183,492
729:18
answer is:183,546
945:18
answer is:183,762
576:18
answer is:184,392
936:18
answer is:184,752
459:18
answer is:186,273
729:18
answer is:186,543
549:18
answer is:187,362
639:18
answer is:187,452
576:18
answer is:192,384
675:18
answer is:192,483
738:18
answer is:192,546
837:18
answer is:192,645
468:18
answer is:193,275
675:18
answer is:193,482
576:18
answer is:194,382
468:18
answer is:195,273
837:18
answer is:195,642
738:18
answer is:196,542
783:18
answer is:214,569
873:18
answer is:214,659
693:18
answer is:215,478
963:18
answer is:215,748
594:18
answer is:216,378
954:18
answer is:216,738
567:18
answer is:218,349
594:18
answer is:218,376
657:18
answer is:218,439
693:18
answer is:218,475
954:18
answer is:218,736
963:18
answer is:218,745
567:18
answer is:219,348
657:18
answer is:219,438
783:18
answer is:219,564
873:18
answer is:219,654
891:18
answer is:234,657
981:18
answer is:235,746
954:18
answer is:236,718
981:18
answer is:236,745
891:18
answer is:237,654
657:18
answer is:238,419
954:18
answer is:238,716
657:18
answer is:239,418
837:18
answer is:241,596
819:18
answer is:243,576
918:18
answer is:243,675
918:18
answer is:245,673
963:18
answer is:245,718
981:18
answer is:245,736
819:18
answer is:246,573
837:18
answer is:246,591
981:18
answer is:246,735
567:18
answer is:248,319
963:18
answer is:248,715
567:18
answer is:249,318
648:18
answer is:251,397
873:18
answer is:254,619
891:18
answer is:254,637
648:18
answer is:257,391
891:18
answer is:257,634
873:18
answer is:259,614
783:18
answer is:264,519
783:18
answer is:269,514
864:18
answer is:271,593
954:18
answer is:271,683
459:18
answer is:273,186
468:18
answer is:273,195
819:18
answer is:273,546
864:18
answer is:273,591
918:18
answer is:273,645
954:18
answer is:273,681
468:18
answer is:275,193
693:18
answer is:275,418
918:18
answer is:275,643
459:18
answer is:276,183
594:18
answer is:276,318
819:18
answer is:276,543
594:18
answer is:278,316
693:18
answer is:278,415
675:18
answer is:281,394
954:18
answer is:281,673
459:18
answer is:283,176
954:18
answer is:283,671
675:18
answer is:284,391
459:18
answer is:286,173
648:18
answer is:291,357
675:18
answer is:291,384
837:18
answer is:291,546
864:18
answer is:291,573
468:18
answer is:293,175
864:18
answer is:293,571
675:18
answer is:294,381
468:18
answer is:295,173
837:18
answer is:296,541
648:18
answer is:297,351
972:18
answer is:314,658
594:18
answer is:316,278
846:18
answer is:317,529
945:18
answer is:317,628
567:18
answer is:318,249
594:18
answer is:318,276
945:18
answer is:318,627
972:18
answer is:318,654
567:18
answer is:319,248
846:18
answer is:319,527
891:18
answer is:324,567
981:18
answer is:324,657
486:18
answer is:327,159
495:18
answer is:327,168
846:18
answer is:327,519
891:18
answer is:327,564
945:18
answer is:327,618
981:18
answer is:327,654
495:18
answer is:328,167
945:18
answer is:328,617
486:18
answer is:329,157
846:18
answer is:329,517
927:18
answer is:341,586
918:18
answer is:342,576
918:18
answer is:346,572
927:18
answer is:346,581
567:18
answer is:348,219
567:18
answer is:349,218
648:18
answer is:351,297
819:18
answer is:352,467
972:18
answer is:354,618
981:18
answer is:354,627
486:18
answer is:357,129
648:18
answer is:357,291
819:18
answer is:357,462
981:18
answer is:357,624
972:18
answer is:358,614
486:18
answer is:359,127
549:18
answer is:362,187
819:18
answer is:362,457
891:18
answer is:364,527
495:18
answer is:367,128
549:18
answer is:367,182
819:18
answer is:367,452
891:18
answer is:367,524
495:18
answer is:368,127
918:18
answer is:372,546
594:18
answer is:376,218
918:18
answer is:376,542
594:18
answer is:378,216
675:18
answer is:381,294
927:18
answer is:381,546
549:18
answer is:382,167
576:18
answer is:382,194
576:18
answer is:384,192
675:18
answer is:384,291
927:18
answer is:386,541
549:18
answer is:387,162
648:18
answer is:391,257
675:18
answer is:391,284
576:18
answer is:392,184
576:18
answer is:394,182
675:18
answer is:394,281
648:18
answer is:397,251
693:18
answer is:415,278
657:18
answer is:418,239
693:18
answer is:418,275
657:18
answer is:419,238
567:18
answer is:428,139
567:18
answer is:429,138
567:18
answer is:438,129
657:18
answer is:438,219
567:18
answer is:439,128
657:18
answer is:439,218
639:18
answer is:452,187
819:18
answer is:452,367
639:18
answer is:457,182
819:18
answer is:457,362
819:18
answer is:462,357
819:18
answer is:467,352
693:18
answer is:475,218
693:18
answer is:478,215
639:18
answer is:482,157
675:18
answer is:482,193
675:18
answer is:483,192
639:18
answer is:487,152
675:18
answer is:492,183
675:18
answer is:493,182
783:18
answer is:514,269
846:18
answer is:517,329
783:18
answer is:519,264
846:18
answer is:519,327
891:18
answer is:524,367
846:18
answer is:527,319
891:18
answer is:527,364
846:18
answer is:529,317
837:18
answer is:541,296
927:18
answer is:541,386
738:18
answer is:542,196
918:18
answer is:542,376
729:18
answer is:543,186
819:18
answer is:543,276
729:18
answer is:546,183
738:18
answer is:546,192
819:18
answer is:546,273
837:18
answer is:546,291
918:18
answer is:546,372
927:18
answer is:546,381
783:18
answer is:564,219
891:18
answer is:564,327
891:18
answer is:567,324
783:18
answer is:569,214
864:18
answer is:571,293
918:18
answer is:572,346
819:18
answer is:573,246
864:18
answer is:573,291
819:18
answer is:576,243
918:18
answer is:576,342
927:18
answer is:581,346
729:18
answer is:583,146
729:18
answer is:586,143
927:18
answer is:586,341
837:18
answer is:591,246
864:18
answer is:591,273
738:18
answer is:592,146
864:18
answer is:593,271
738:18
answer is:596,142
837:18
answer is:596,241
873:18
answer is:614,259
972:18
answer is:614,358
945:18
answer is:617,328
945:18
answer is:618,327
972:18
answer is:618,354
873:18
answer is:619,254
783:18
answer is:624,159
981:18
answer is:624,357
945:18
answer is:627,318
981:18
answer is:627,354
945:18
answer is:628,317
783:18
answer is:629,154
792:18
answer is:634,158
891:18
answer is:634,257
891:18
answer is:637,254
792:18
answer is:638,154
837:18
answer is:642,195
918:18
answer is:643,275
837:18
answer is:645,192
918:18
answer is:645,273
783:18
answer is:654,129
792:18
answer is:654,138
873:18
answer is:654,219
891:18
answer is:654,237
972:18
answer is:654,318
981:18
answer is:654,327
891:18
answer is:657,234
981:18
answer is:657,324
792:18
answer is:658,134
972:18
answer is:658,314
783:18
answer is:659,124
873:18
answer is:659,214
954:18
answer is:671,283
918:18
answer is:673,245
954:18
answer is:673,281
918:18
answer is:675,243
954:18
answer is:681,273
954:18
answer is:683,271
837:18
answer is:692,145
837:18
answer is:695,142
963:18
answer is:715,248
954:18
answer is:716,238
954:18
answer is:718,236
963:18
answer is:718,245
864:18
answer is:725,139
864:18
answer is:729,135
864:18
answer is:735,129
981:18
answer is:735,246
954:18
answer is:736,218
981:18
answer is:736,245
954:18
answer is:738,216
864:18
answer is:739,125
963:18
answer is:745,218
981:18
answer is:745,236
981:18
answer is:746,235
963:18
answer is:748,215
936:18
answer is:752,184
936:18
answer is:754,182
945:18
answer is:762,183
945:18
answer is:763,182
936:18
answer is:782,154
945:18
answer is:782,163
945:18
answer is:783,162
936:18
answer is:784,152
total check:60480
answer count:336

  • 大小: 119.9 KB
0
1
分享到:
评论

相关推荐

    中小学数学题程序_instance62k_python题_Python解数学题_Python解奥数题_python解初中题_

    在Python编程领域,解决中小学数学题,包括奥数题和初中数学题,是一种常见的实践,旨在提高编程技能和逻辑思维能力。"instance62k_python题"可能指的是一个包含62000个数学问题的实例集合,这些题目涵盖了从小学到...

    java程序设计填空题题库49道

    Java程序设计涵盖了许多核心概念,包括: 1. **包与集合框架**:`...以上知识点覆盖了Java语言的基础语法、面向对象编程、输入输出、图形用户界面、线程管理和类的定义与使用等多个方面,是学习Java程序设计的基础。

    java 控制台实现小学数学加减法题目随机生成并在计算后给出得分【源码+报告】

    可以选择考试类型:1、练习 2、测试 可以选择计算类型:01、一位数的加法或减法 02、两位数的加法或减法 03、混合计算 04、程序结束 根据选择的计算类型,会随机生成不同位数的加减法题目 计算之后,会给出得分

    小学三年级奥数题100道.pdf

    小学三年级奥数题100道.pdf

    小学数学奥数题 有答案PPT教案.pptx

    在这一背景下,小学数学奥数题的提出,不仅旨在丰富学生的数学知识,更重要的是,通过解决这些挑战性的题目,学生的思维能力和创新精神得到了锻炼。本文将深入解析小学数学奥数题中的几种常用解题策略,包括抓“不...

    基于Java+Swing的小学数学题练习系统(源码+报告+包运行成功)

    这个资源是一个基于Java编程语言和Swing图形用户界面库开发的小学数学题练习系统。它包含了完整的源代码、详细的报告。通过这个系统,可以进行小学数学题的练习,包括加法、减法、乘法、除法等数学题。 主要功能:...

    最新JAVA编程题及答案

    综合来看,这些编程题目都围绕着Java编程语言的基础知识点,包括循环控制(for和while)、条件判断、数学运算以及基本的算法设计。掌握这些内容对于Java程序员来说至关重要,因为它们是日常工作中的基础工具。此外,...

    小学数学四年级[上册]奥数题与答案100道.pdf

    小学数学四年级[上册]奥数题与答案100道.pdf

    小学三年级数学奥数题附答案.pdf

    小学三年级数学奥数题附答案.pdf

    JAVA编程题全集(100题及答案).doc

    这道题目考察了 Java 程序中面向对象编程的设计和实现能力。 本资源提供了涵盖了 Java 基础知识、控制结构、函数、数组、面向对象编程等多方面的知识点,能够帮助学习者全面地了解 Java 程序设计的基本概念和编程...

    vb课程设计报告(小学数学成绩测试)

    【VB课程设计报告——小学数学成绩测试】 VB(Visual Basic)是一种由微软开发的编程环境,用于创建Windows应用程序。在这个VB课程设计项目中,学生被要求设计一个小型测试系统,专注于小学数学成绩的管理和测试。...

    java小学数学练习

    这是基本学习完javase,java基础后做的简易java项目,里面具体实现的功能是1-100以内的加减,乘除方法有但是没有搭建界面,以及一个模式金山打字的练习字母的小游戏。初学java,如有不足还请见谅!

    小学生数学测试软件(Java编写)

    通过以上分析,我们可以得出这个软件是一个结合了Java编程技术和小学数学教育的实用工具,旨在通过互动方式帮助小学生提高数学运算能力,同时具备一定的定制化功能,以满足不同用户的需求。对于开发者来说,它是Java...

    JAVA课程设计——小学生数学练习题目自动生成系统

    编写一个能够自动生成小学生数学练习题目的程序。设计一个程序,能够根据用户的选择生成“10以内加法”、“10以内减法”、“20以内加法”、“20以内减法”、“100以内加法”、“100以内减法”、“100以内乘法”、...

    小学生数学考试自动系统java大作业.zip

    1、采用图形用户界面,界面标题为“广州市X小学数学考试自动系统”,主要功能为:自动生成50道数学题,每题为随机生成的3个100以内整数的加减混合运算,每道题为2分,共100分,考试时间为90分钟。 2、系统基本功能...

    经典java编程练习题

    Java编程练习题涵盖了Java编程的方方面面,对程序员的Java基础知识、控制结构、数组和集合、面向对象编程、字符串和正则表达式、文件和输入/输出、数学运算、递归和算法、数据结构和算法等知识点进行了考核。

    Java基于ssm+mysql的协同过滤算法的离散数学题推荐系统的实现.zip

    Java基于ssm+mysql的协同过滤算法的离散数学题推荐系统的实现.zipJava基于ssm+mysql的协同过滤算法的离散数学题推荐系统的实现.zipJava基于ssm+mysql的协同过滤算法的离散数学题推荐系统的实现.zipJava基于ssm+mysql...

    java基础编程题java基础编程题.doc

    马克思手稿中有一道趣味数学问题是Java基础编程题中的一道题目,它考察了程序员对数学运算和逻辑思维的理解。通过解决马克思手稿中的一道趣味数学问题,我们可以了解Java中的数学运算和逻辑思维等。 7. 正的九九...

    小学数学计算题.pdf

    通过《小学数学计算题.pdf》,学生能够通过解决各种数学计算题来加深对基础数学概念的理解,提升计算技能,从而为进一步的数学学习打下坚实的基础。 该资源以一种结构化和系统化的方式编排,分为五个部分,每个部分...

Global site tag (gtag.js) - Google Analytics