当前位置:网站首页>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])上面的程序给出了比较详细的注释,以便新手小白参考。程序的思路设计或者代码实现并不是最优的,欢迎各位大佬指正错误或者给出更优质的思路。
我是一只想成为鲲鹏的菜鸟,大家的鼓励是我前进的动力,欢迎大家点赞收藏评论哦!
边栏推荐
- 20220211-CTF-MISC-006-pure_ Color (use of stegsolve tool) -007 Aesop_ Secret (AES decryption)
- Have you encountered ABA problems? Let's talk about the following in detail, how to avoid ABA problems
- 深度强化文献阅读系列(一):Courier routing and assignment for food delivery service using reinforcement learning
- 【九阳神功】2019复旦大学应用统计真题+解析
- [during the interview] - how can I explain the mechanism of TCP to achieve reliable transmission
- This time, thoroughly understand the MySQL index
- The difference between overloading and rewriting
- Safe driving skills on ice and snow roads
- [the Nine Yang Manual] 2020 Fudan University Applied Statistics real problem + analysis
- The difference between abstract classes and interfaces
猜你喜欢

Relationship between hashcode() and equals()

ABA问题遇到过吗,详细说以下,如何避免ABA问题

MATLAB打开.m文件乱码解决办法

The difference between cookies and sessions
![[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP](/img/d6/109042b77de2f3cfbf866b24e89a45.png)
[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP

Questions and answers of "signal and system" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology

C语言入门指南

3. Number guessing game

使用Spacedesk实现局域网内任意设备作为电脑拓展屏

2.C语言矩阵乘法
随机推荐
Questions and answers of "Fundamentals of RF circuits" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
The difference between cookies and sessions
[the Nine Yang Manual] 2018 Fudan University Applied Statistics real problem + analysis
FAQs and answers to the imitation Niuke technology blog project (I)
Questions and answers of "basic experiment" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
TypeScript快速入门
Mode 1 two-way serial communication is adopted between machine a and machine B, and the specific requirements are as follows: (1) the K1 key of machine a can control the ledi of machine B to turn on a
Thoroughly understand LRU algorithm - explain 146 questions in detail and eliminate LRU cache in redis
3.C语言用代数余子式计算行列式
ArrayList的自动扩容机制实现原理
【九阳神功】2019复旦大学应用统计真题+解析
[modern Chinese history] Chapter 9 test
Change vs theme and set background picture
Arduino+ds18b20 temperature sensor (buzzer alarm) +lcd1602 display (IIC drive)
重载和重写的区别
Mortal immortal cultivation pointer-1
fianl、finally、finalize三者的区别
Implementation principle of automatic capacity expansion mechanism of ArrayList
稻 城 亚 丁
canvas基础1 - 画直线(通俗易懂)