当前位置:网站首页>7-9 制作门牌号3.0(PTA程序设计)
7-9 制作门牌号3.0(PTA程序设计)
2022-07-06 09:22:00 【编程林黛玉】
我们想给一条街的住户编制门牌号,从1号编起,一直到这条街的住户总数。
制作门牌号的方法是先制作0到9这十个数字字符,然后根据需要将字符贴到门牌上,例如门牌808号是以此粘贴字符8,0,8。这就需要2个字符8,一个字符0。
请问要制作所有的门牌号,从0到9这十个数字字符各需要多少个?
输入格式:
输入这条街住户总数正整数A。
输出格式:
对于每一个正整数A,输出两行,第一行为0到9这十个数字字符,第二行为这十个数字字符分别需要的个数。
输入样例1:
在这里给出一组输入。例如:
1
输出样例1:
在这里给出相应的输出。例如:
0 1 2 3 4 5 6 7 8 9
0 1 0 0 0 0 0 0 0 0
输入样例2:
在这里给出一组输入。例如:
2022
输出样例2:
在这里给出相应的输出。例如:
0 1 2 3 4 5 6 7 8 9
525 1613 629 602 602 602 602 602 602 602
代码(Python):
n=int(input()) #输入这条街住户总数正整数n
list1=[0,0,0,0,0,0,0,0,0,0] #因为所有数字都是0~9这9个数字构成,所以先声明一个长度为0的列表,并初始化为0,用来存放各个数字出现的次数
while n>0: #从n开始判断,一直判断到0
m=n #先保存一个n的值,在下面while循环中用m,以免破坏n的值
while m>0:
i=m%10 #取该数的最末位
list1[i]+=1 #求余得几就表示末尾是几,就在列表的第几位加1
m=m//10 #将最后1位去掉,以便让倒数第二位成为倒数第一位继续判断
n-=1 #退出循环表示已经记录完n里的每一个数,再判断下一个数
print("0 1 2 3 4 5 6 7 8 9") #因为所有数字都是0~9这9个数字构成,所以先输出这9个数字,即输出样例中的第一行
for i in range(len(list1)): #输出对应次数
if i!=9: #非最后一个数字,输出该数字,并以空格结尾
print(list1[i],end=' ')
else: #输出的最后一个数末尾没有空格,直接换行
print(list1[i])上面的程序给出了比较详细的注释,以便新手小白参考。程序的思路设计或者代码实现并不是最优的,欢迎各位大佬指正错误或者给出更优质的思路。
我是一只想成为鲲鹏的菜鸟,大家的鼓励是我前进的动力,欢迎大家点赞收藏评论哦!
边栏推荐
- Wei Pai: the product is applauded, but why is the sales volume still frustrated
- 【九阳神功】2021复旦大学应用统计真题+解析
- Using qcommonstyle to draw custom form parts
- ArrayList的自动扩容机制实现原理
- Inaki Ading
- 2.初识C语言(2)
- 4.二分查找
- canvas基础2 - arc - 画弧线
- 5月14日杂谈
- (original) make an electronic clock with LCD1602 display to display the current time on the LCD. The display format is "hour: minute: Second: second". There are four function keys K1 ~ K4, and the fun
猜你喜欢

Pit avoidance Guide: Thirteen characteristics of garbage NFT project

Have you encountered ABA problems? Let's talk about the following in detail, how to avoid ABA problems

1.C语言矩阵加减法

这次,彻底搞清楚MySQL索引

仿牛客技术博客项目常见问题及解答(二)

4.二分查找

PriorityQueue (large root heap / small root heap /topk problem)

Write a program to simulate the traffic lights in real life.

2022泰迪杯数据挖掘挑战赛C题思路及赛后总结

hashCode()与equals()之间的关系
随机推荐
优先队列PriorityQueue (大根堆/小根堆/TopK问题)
【黑马早报】上海市监局回应钟薛高烧不化;麦趣尔承认两批次纯牛奶不合格;微信内测一个手机可注册俩号;度小满回应存款变理财产品...
The latest tank battle 2022 full development notes-1
8.C语言——位操作符与位移操作符
ABA问题遇到过吗,详细说以下,如何避免ABA问题
MySQL锁总结(全面简洁 + 图文详解)
Leetcode. 3. Longest substring without repeated characters - more than 100% solution
1. C language matrix addition and subtraction method
[graduation season · advanced technology Er] goodbye, my student days
Redis实现分布式锁原理详解
.Xmind文件如何上传金山文档共享在线编辑?
受检异常和非受检异常的区别和理解
Difference and understanding between detected and non detected anomalies
Detailed explanation of redis' distributed lock principle
5. Function recursion exercise
There is always one of the eight computer operations that you can't learn programming
简单理解ES6的Promise
2. C language matrix multiplication
自定义RPC项目——常见问题及详解(注册中心)
hashCode()与equals()之间的关系