当前位置: 首页 > news >正文

网站构思线上销售渠道

网站构思,线上销售渠道,渝北区两江新区,上海人才信息网官网数字分组求偶数和 1.问题描述 问题描述 小M面对一组从 1 到 9 的数字#xff0c;这些数字被分成多个小组#xff0c;并从每个小组中选择一个数字组成一个新的数。目标是使得这个新数的各位数字之和为偶数。任务是计算出有多少种不同的分组和选择方法可以达到这一目标。 n…数字分组求偶数和 1.问题描述 问题描述 小M面对一组从 1 到 9 的数字这些数字被分成多个小组并从每个小组中选择一个数字组成一个新的数。目标是使得这个新数的各位数字之和为偶数。任务是计算出有多少种不同的分组和选择方法可以达到这一目标。 numbers: 一个由多个整数字符串组成的列表每个字符串可以视为一个数字组。小M需要从每个数字组中选择一个数字。 例如对于[123, 456, 789]14个符合条件的数为147 149 158 167 169 248 257 259 268 347 349 358 367 369。 测试样例 样例1 输入numbers [123, 456, 789] 输出14 样例2 输入numbers [123456789] 输出4 样例3 输入numbers [14329, 7568] 输出10 2.思路与题解 问题理解 你需要从每个数字组中选择一个数字使得这些数字的和为偶数。问题的核心在于如何判断一个数的和是否为偶数。 数据结构选择 输入是一个整数数组每个整数可以转换为字符串来处理。你需要遍历每个数字组并从每个组中选择一个数字。 算法步骤 转换输入将整数数组转换为字符串数组以便于处理每个数字组中的单个数字。递归遍历使用递归函数来遍历每个数字组并从每个组中选择一个数字。和的判断在递归过程中累加当前选择的数字并在递归的终止条件处判断累加和是否为偶数。计数如果累加和为偶数则计数加一。 2.4代码框架 Java public class Main {public static int solution(int[] numbers) {// 将整数数组转换为字符串数组String[] numStrings new String[numbers.length];for (int i 0; i numbers.length; i) {numStrings[i] String.valueOf(numbers[i]);}// 调用递归函数进行计算return countEvenSumCombinations(numStrings, 0, 0);}// 递归函数用于计算符合条件的组合数private static int countEvenSumCombinations(String[] numStrings, int index, int currentSum) {// 如果已经遍历完所有数字组if (index numStrings.length) {// 检查当前和是否为偶数if (currentSum % 2 0) {return 1;} else {return 0;}}int count 0;// 遍历当前数字组中的每个数字for (char digit : numStrings[index].toCharArray()) {// 将字符转换为数字int num digit - 0;// 递归调用选择下一个数字组count countEvenSumCombinations(numStrings, index 1, currentSum num);}return count;}public static void main(String[] args) {// 测试用例System.out.println(solution(new int[]{123, 456, 789}) 14);System.out.println(solution(new int[]{123456789}) 4);System.out.println(solution(new int[]{14329, 7568}) 10);} }C #include iostream #include vector #include stringint solution(std::vectorint numbers) {int count 0;// 遍历每个数字组for (int num : numbers) {std::string numStr std::to_string(num);// 遍历数字组中的每个数字for (char digit : numStr) {// 计算和int sum 0;// 计算各位数字之和// 判断和是否为偶数if (sum % 2 0) {count;}}}return count; }int main() {// You can add more test cases herestd::cout (solution({123, 456, 789}) 14) std::endl;std::cout (solution({123456789}) 4) std::endl;std::cout (solution({14329, 7568}) 10) std::endl;return 0; }Python def solution(numbers):def is_even_sum(digits):# 检查一组数字的和是否为偶数return sum(digits) % 2 0def count_even_sum_combinations(index, current_digits):# 如果已经遍历完所有数字组if index len(numbers):# 检查当前组合的和是否为偶数if is_even_sum(current_digits):return 1return 0count 0# 遍历当前数字组中的每个数字for digit in str(numbers[index]):# 选择当前数字并递归处理下一个数字组count count_even_sum_combinations(index 1, current_digits [int(digit)])return count# 从第一个数字组开始递归计算return count_even_sum_combinations(0, [])if __name__ __main__:# 你可以添加更多测试用例print(solution([123, 456, 789]) 14)print(solution([123456789]) 4)print(solution([14329, 7568]) 10)Golang package mainimport fmtfunc solution(numbers []int) int {// 辅助函数用于判断一个数是否为偶数isEven : func(num int) bool {return num%2 0}// 递归函数用于遍历所有可能的选择var dfs func(index int, currentSum int) intdfs func(index int, currentSum int) int {// 如果已经遍历完所有数字组if index len(numbers) {// 检查当前和是否为偶数if isEven(currentSum) {return 1}return 0}count : 0// 将当前数字组转换为字符串numStr : fmt.Sprintf(%d, numbers[index])// 遍历当前数字组中的每个数字for i : 0; i len(numStr); i {// 将字符转换为数字digit : int(numStr[i] - 0)// 递归处理下一个数字组count dfs(index1, currentSumdigit)}return count}// 从第一个数字组开始递归return dfs(0, 0) }func main() {// 你可以添加更多测试用例fmt.Println(solution([]int{123, 456, 789}) 14)fmt.Println(solution([]int{123456789}) 4)fmt.Println(solution([]int{14329, 7568}) 10) }2.5一些疑难的代码解释 递归函数的设计确保递归函数能够正确地遍历每个数字组并累加当前选择的数字。和的判断在递归的终止条件处判断累加和是否为偶数。计数如果累加和为偶数则计数加一。 3.欢迎大佬们关注或莅临本渣的一些个人website gitee https://gitee.com/xiao-chenago githubhttps://github.com/cool-icu0 语雀https://www.yuque.com/icu0 csdnhttps://cool-icu.blog.csdn.net/
文章转载自:
http://www.morning.mlbn.cn.gov.cn.mlbn.cn
http://www.morning.trffl.cn.gov.cn.trffl.cn
http://www.morning.plcyq.cn.gov.cn.plcyq.cn
http://www.morning.kdrjd.cn.gov.cn.kdrjd.cn
http://www.morning.ywzqk.cn.gov.cn.ywzqk.cn
http://www.morning.dlurfdo.cn.gov.cn.dlurfdo.cn
http://www.morning.mttqp.cn.gov.cn.mttqp.cn
http://www.morning.hqllx.cn.gov.cn.hqllx.cn
http://www.morning.kjyqr.cn.gov.cn.kjyqr.cn
http://www.morning.drbd.cn.gov.cn.drbd.cn
http://www.morning.kqzt.cn.gov.cn.kqzt.cn
http://www.morning.c7513.cn.gov.cn.c7513.cn
http://www.morning.rdzlh.cn.gov.cn.rdzlh.cn
http://www.morning.mqwnz.cn.gov.cn.mqwnz.cn
http://www.morning.wjhdn.cn.gov.cn.wjhdn.cn
http://www.morning.gl-group.cn.gov.cn.gl-group.cn
http://www.morning.qdrhf.cn.gov.cn.qdrhf.cn
http://www.morning.ntzfj.cn.gov.cn.ntzfj.cn
http://www.morning.gqtxz.cn.gov.cn.gqtxz.cn
http://www.morning.skrrq.cn.gov.cn.skrrq.cn
http://www.morning.pybqq.cn.gov.cn.pybqq.cn
http://www.morning.nrftd.cn.gov.cn.nrftd.cn
http://www.morning.qwlml.cn.gov.cn.qwlml.cn
http://www.morning.dkbsq.cn.gov.cn.dkbsq.cn
http://www.morning.zlqyj.cn.gov.cn.zlqyj.cn
http://www.morning.yktwr.cn.gov.cn.yktwr.cn
http://www.morning.dyxlj.cn.gov.cn.dyxlj.cn
http://www.morning.pzrnf.cn.gov.cn.pzrnf.cn
http://www.morning.bpttm.cn.gov.cn.bpttm.cn
http://www.morning.wflpj.cn.gov.cn.wflpj.cn
http://www.morning.xckdn.cn.gov.cn.xckdn.cn
http://www.morning.gybnk.cn.gov.cn.gybnk.cn
http://www.morning.nlygm.cn.gov.cn.nlygm.cn
http://www.morning.zyrp.cn.gov.cn.zyrp.cn
http://www.morning.fthcn.cn.gov.cn.fthcn.cn
http://www.morning.rwrn.cn.gov.cn.rwrn.cn
http://www.morning.ljqd.cn.gov.cn.ljqd.cn
http://www.morning.sgnxl.cn.gov.cn.sgnxl.cn
http://www.morning.zjcmr.cn.gov.cn.zjcmr.cn
http://www.morning.mjgxl.cn.gov.cn.mjgxl.cn
http://www.morning.dqcpm.cn.gov.cn.dqcpm.cn
http://www.morning.ltrms.cn.gov.cn.ltrms.cn
http://www.morning.thbnt.cn.gov.cn.thbnt.cn
http://www.morning.jzfrl.cn.gov.cn.jzfrl.cn
http://www.morning.gqfjb.cn.gov.cn.gqfjb.cn
http://www.morning.jcypk.cn.gov.cn.jcypk.cn
http://www.morning.ygth.cn.gov.cn.ygth.cn
http://www.morning.bkpbm.cn.gov.cn.bkpbm.cn
http://www.morning.drytb.cn.gov.cn.drytb.cn
http://www.morning.kstgt.cn.gov.cn.kstgt.cn
http://www.morning.gwkjg.cn.gov.cn.gwkjg.cn
http://www.morning.nrzkg.cn.gov.cn.nrzkg.cn
http://www.morning.msgnx.cn.gov.cn.msgnx.cn
http://www.morning.rwls.cn.gov.cn.rwls.cn
http://www.morning.glcgy.cn.gov.cn.glcgy.cn
http://www.morning.mgzjz.cn.gov.cn.mgzjz.cn
http://www.morning.jqkjr.cn.gov.cn.jqkjr.cn
http://www.morning.pxwzk.cn.gov.cn.pxwzk.cn
http://www.morning.btrfm.cn.gov.cn.btrfm.cn
http://www.morning.sypzg.cn.gov.cn.sypzg.cn
http://www.morning.bchhr.cn.gov.cn.bchhr.cn
http://www.morning.xtkw.cn.gov.cn.xtkw.cn
http://www.morning.znknj.cn.gov.cn.znknj.cn
http://www.morning.hmmtx.cn.gov.cn.hmmtx.cn
http://www.morning.srndk.cn.gov.cn.srndk.cn
http://www.morning.mqxzh.cn.gov.cn.mqxzh.cn
http://www.morning.cmfkp.cn.gov.cn.cmfkp.cn
http://www.morning.gcqkb.cn.gov.cn.gcqkb.cn
http://www.morning.dkslm.cn.gov.cn.dkslm.cn
http://www.morning.lpgw.cn.gov.cn.lpgw.cn
http://www.morning.dtrcl.cn.gov.cn.dtrcl.cn
http://www.morning.lxfyn.cn.gov.cn.lxfyn.cn
http://www.morning.ckzjl.cn.gov.cn.ckzjl.cn
http://www.morning.fhqdb.cn.gov.cn.fhqdb.cn
http://www.morning.kyhnl.cn.gov.cn.kyhnl.cn
http://www.morning.bygyd.cn.gov.cn.bygyd.cn
http://www.morning.ylkkh.cn.gov.cn.ylkkh.cn
http://www.morning.qpnmd.cn.gov.cn.qpnmd.cn
http://www.morning.cjqcx.cn.gov.cn.cjqcx.cn
http://www.morning.dkzrs.cn.gov.cn.dkzrs.cn
http://www.tj-hxxt.cn/news/242546.html

相关文章:

  • 制作单网页网站html5网站建设 教程
  • 玉山县建设局的网站wordpress顶部图片轮播
  • 建筑网站汇总北滘网站建设公司
  • 模板设计原则湖州网站seo优化
  • 株洲市天元区建设局网站高要区公路建设规划局网站
  • 网站建设中药尽量使用图片专门做ppt的网站
  • 做网站怎样实现网上支付做棋牌游戏网站犯法吗
  • 为什么做网站费用贵外贸网络营销实战
  • 做原创的网站百度网页大全
  • 那家建设网站p2p公司最好公司视频宣传片
  • 平度做网站公司有哪些外国网站做精油的
  • 网站域名注册证书查询网站本科报考官网
  • 承德网站建设作用90设计网站怎么样
  • 做网站 教程在线教育网站建设
  • 网站模板源代码wordpress一键分享
  • 电子政务和网站建设工作的总结软件商店下载安装免费
  • 网上商城网站设计手机网站如何生成app
  • 网站建设个人网站wordpress积分交换
  • 凯里网站建设gzklyy基于asp.net网站开发视频教程
  • 网站建设用户登录源码网站开发不提供源代码
  • 网站报错500郴州新网招聘网最新招聘信息
  • 昆明网站设计都需要设计什么WordPress外链转内链插件
  • 怎么做网站免宠物用品销售网站建设和技术现状
  • 广州天河区有什么好玩的没有网站可以做seo吗
  • 网络推广公司企业深圳seo论坛
  • 卖狗做网站什么关键词最好光谷做网站推广公司
  • 网站管理后台登录地址王者荣耀网站开发目的
  • 深圳松岗做网站江苏网页设计公司
  • 微信开发公司aso优化渠道
  • 网站做授权登录wordpress拖拽式