当前位置:网站首页>输出1234无重复的三位数
输出1234无重复的三位数
2022-07-29 07:35:00 【算法与编程之美】
引言
在解决数学排列组合时,遇到求给出1,2,3,4四个数字组成重复的三位数的个数时,可以用编程的方法来解决类似的问题,还能验证答案是否正确。
1 问题
用1,2,3,4四个数字组成无重复的三位数,求能组成多少个这样的数。
2 方法
先给定一个列表,第一个循环得到第一个数,第二个循环得到第二个数,第三个循环得到第三个数,用if条件语句进行判断三个数是否重复或者相等,然后再将其转化为三位数,添加到列表中,最后输出该列表得到结果。
3 实验结果与讨论
通过实验、实践等证明提出的方法是有效的,是能够解决开头提出的问题。
代码清单 1
| List=[] for i in range(1,5): for m in range(1,5): for i in range()1,5: if i!=m and i!=n and m!=n: x=(i*100+m*10+n) list.append() print(list) print(‘能生成%d个’%int(len(list))) |
4 结语
探讨了1234能够组成多少个无重复的三位数,涉及到for循环、if条件判断语句以及字符串之间的转换,进一步巩固了这些知识点,通过数学方法排列组合得出的结果与该程序运行的结果相一致,证明该方法是有效的解决该问题。
边栏推荐
- 3-global exception handling
- PAT甲级 1150 旅行商问题
- Female graduate students do "mind mapping" and quarrel with their boyfriend! Netizen: the "king of infighting" in the quarrel
- 写点dp
- 梳理市面上的2大NFT定价范式和4种解决方案
- QT topic: basic components (button class, layout class, output class, input class, container class)
- Job 7.28 file IO and standard IO
- EF core reading text type is slow_ EF core is slow to read large string fields
- Logback log level introduction
- Meta configuration item of route
猜你喜欢

Thinkphp6 realizes database backup

国内数字藏品的乱象与未来

log4qt内存泄露问题,heob内存检测工具的使用
![【暑期每日一题】洛谷 P7760 [COCI2016-2017#5] Tuna](/img/9a/f857538c574fb54bc1accb737d7aec.png)
【暑期每日一题】洛谷 P7760 [COCI2016-2017#5] Tuna

A long article --- in-depth understanding of synchronized

监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)

What are the answers about older bloggers?

Halcon installation and testing in vs2017, DLL configuration in vs2017

电子元器件贸易企业如何借助ERP系统,解决仓库管理难题?
Scala higher order (IX): pattern matching in Scala
随机推荐
Does Flink support sqlserver databases? Get the changes of SQLSERVER database
程序的静态库与动态库的区别
PAT甲级 1146 拓扑顺序
Introduction to logback appender
Introduction and introduction of logback
基于高阶无六环的LDPC最小和译码matlab仿真
[summer daily question] Luogu p4414 [coci2006-2007 2] ABC
webapi接口文件下载时跨域问题
【WPF】通过动态/静态资源实现语言切换
How to establish EDI connection with Scania in Scania?
State machine DP (simple version)
【暑期每日一题】洛谷 P7760 [COCI2016-2017#5] Tuna
Leetcode buckle classic problem -- 4. Find the median of two positively ordered arrays
Scala 高阶(十):Scala中的异常处理
【暑期每日一题】洛谷 P4414 [COCI2006-2007#2] ABC
mysql 使用 DATE_FORMAT(date,'%Y-%m')
反射reflect
Amazon cloud assistant applet is coming!
Description of rollingfileappender attribute in logback
Android面试题 | 怎么写一个又好又快的日志库?