多个长度集合拼接出想要长度的组合
2021/7/14 6:08:21
本文主要是介绍多个长度集合拼接出想要长度的组合,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
多个长度集合拼接出想要长度的组合
import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @program: world * @description: 多个长度集合拼接出想要长度的组合 * @author: XinHai.Ma * @create: 2021-07-11 21:41 */ @SuppressWarnings("all") public class CountTests { private static final Logger logger = LoggerFactory.getLogger(CountTests.class); public static void main(String[] args) { // 8种长度模具 int[] nums = new int[8]; nums[0] = 10; nums[1] = 11; nums[2] = 12; nums[3] = 13; nums[4] = 14; nums[5] = 15; nums[6] = 7; nums[7] = 8; // 顺序模具 int[] nums1 = new int[8]; nums1[0] = 7; nums1[1] = 8; nums1[2] = 10; nums1[3] = 11; nums1[4] = 12; nums1[5] = 13; nums1[6] = 14; nums1[7] = 15; int totalLen1 = 36; // 40 int totalLen2 = 36; // 42 for (int j = 0; j < nums.length; j++) { if(j <= nums.length-4) { int total = nums[j] + nums[j+1] + nums[j+2] + nums[j+3]; if(total <= totalLen2) { logger.info("{}={}+{}+{}+{}", total, nums[j], nums[j+1], nums[j+2], nums[j+3]); } } for(int i=j+2; i < nums.length; i++) { if(i <= nums.length-3) { int total = nums[j] + nums[i] + nums[i+1] + nums[i+2]; if(total <= totalLen2) { logger.info("{}={}+{}+{}+{}", total, nums[j], nums[i], nums[i+1], nums[i+2]); } } } } for (int j = 0; j < nums.length; j++) { if(j <= nums.length-3) { int total = nums[j] + nums[j+1] + nums[j+2]; if(total <= totalLen2) { logger.info("{}={}+{}+{}", total, nums[j], nums[j+1], nums[j+2]); } int num = totalLen1 - total; int num1 = totalLen2 - total; for (int i1 = nums1.length-1; i1 >= 0; i1--) { if(num >= nums1[i1] && ((nums1[i1]+total) <= totalLen1)) { logger.info("{}={}+{}+{}+{}", total, nums[j], nums[j+1], nums[j+2], nums1[i1]); } if(num1 >= nums1[i1] && ((nums1[i1]+total) <= totalLen2)) { logger.info("{}={}+{}+{}+{}", total, nums[j], nums[j+1], nums[j+2], nums1[i1]); } } } for(int i=j+2; i < nums.length; i++) { if(i <= nums.length-2) { int total = nums[j] + nums[i] + nums[i+1]; if(total <= totalLen1) { logger.info("{}={}+{}+{}", total, nums[j], nums[i], nums[i+1]); } int num = totalLen1 - total; int num1 = totalLen2 - total; for (int i1 = nums1.length-1; i1 >= 0; i1--) { if(num >= nums1[i1] && ((nums1[i1]+total) <= totalLen1)) { logger.info("{}={}+{}+{}+{}", total, nums[j], nums[i], nums[i+1], nums1[i1]); } if(num1 >= nums1[i1] && ((nums1[i1]+total) <= totalLen2)) { logger.info("{}={}+{}+{}+{}", total, nums[j], nums[i], nums[i+1], nums1[i1]); } } } } } } }
计算结果
23:10:26.420 [main] INFO com.maxinhai.world.CountTests - 33=10+11+12 23:10:26.423 [main] INFO com.maxinhai.world.CountTests - 35=10+12+13 23:10:26.423 [main] INFO com.maxinhai.world.CountTests - 32=10+15+7 23:10:26.423 [main] INFO com.maxinhai.world.CountTests - 25=10+7+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 25=10+7+8+11 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 25=10+7+8+11 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 25=10+7+8+10 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 25=10+7+8+10 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 25=10+7+8+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 25=10+7+8+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 25=10+7+8+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 25=10+7+8+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 36=11+12+13 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 33=11+15+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 26=11+7+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 26=11+7+8+10 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 26=11+7+8+10 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 26=11+7+8+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 26=11+7+8+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 26=11+7+8+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 26=11+7+8+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 34=12+15+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 27=12+7+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 27=12+7+8+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 27=12+7+8+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 27=12+7+8+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 27=12+7+8+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 35=13+15+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 28=13+7+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 28=13+7+8+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 28=13+7+8+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 28=13+7+8+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 28=13+7+8+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 36=14+15+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 29=14+7+8 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 29=14+7+8+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 29=14+7+8+7 23:10:26.424 [main] INFO com.maxinhai.world.CountTests - 30=15+7+8
这篇关于多个长度集合拼接出想要长度的组合的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-10百万架构师第十三课:源码分析:Spring 源码分析:Spring核心IOC容器及依赖注入原理|JavaGuide
- 2025-01-10便捷好用的电商API工具合集
- 2025-01-09必试!帮 J 人团队解决物流错发漏发的软件神器!
- 2025-01-09不容小觑!助力 J 人物流客服安抚情绪的软件!
- 2025-01-09为什么医疗团队协作离不开智能文档工具?
- 2025-01-09惊叹:J 人团队用啥软件让物流服务快又准?
- 2025-01-09如何利用数据分析工具优化项目资源分配?4种工具推荐
- 2025-01-09多学科协作难?这款文档工具可以帮你省心省力
- 2025-01-09团队中的技术项目经理TPM:工作内容与资源优化策略
- 2025-01-09JIT生产管理法:优化流程,提升竞争力的秘诀