当前位置:网站首页>7-9 make house number 3.0 (PTA program design)
7-9 make house number 3.0 (PTA program design)
2022-07-06 13:56:00 【Programming Lindaiyu】
We want to number the residents in a street , from 1 From serial number , The total number of households up to this street .
The method of making house number is to make 0 To 9 These ten numeric characters , Then paste the characters on the doorplate as needed , For example, the house number 808 The number is used to paste characters 8,0,8. This requires 2 Characters 8, A character 0.
Please make all the house numbers , from 0 To 9 How many of these ten numeric characters are needed ?
Input format :
Enter the positive integer of the total number of households in this street A.
Output format :
For every positive integer A, Output two lines , First act 0 To 9 These ten numeric characters , The second line is the number of these ten numeric characters .
sample input 1:
Here's a set of inputs . for example :
1
sample output 1:
Here is the corresponding output . for example :
0 1 2 3 4 5 6 7 8 9
0 1 0 0 0 0 0 0 0 0
sample input 2:
Here's a set of inputs . for example :
2022
sample output 2:
Here is the corresponding output . for example :
0 1 2 3 4 5 6 7 8 9
525 1613 629 602 602 602 602 602 602 602
Code (Python):
n=int(input()) # Enter the positive integer of the total number of households in this street n
list1=[0,0,0,0,0,0,0,0,0,0] # Because all the numbers are 0~9 this 9 Numbers make up , So first declare a length of 0 A list of , And initialize to 0, Used to store the number of times each number appears
while n>0: # from n Start judging , Judge until 0
m=n # Save one first n Value , Hereunder while Use... In circulation m, So as not to destroy n Value
while m>0:
i=m%10 # Take the last digit of the number
list1[i]+=1 # Finding the remainder means that the end is , Add 1
m=m//10 # Will last 1 Bit removal , In order to make the penultimate place become the penultimate place and continue to judge
n-=1 # Exiting the loop means that the record has been completed n Every number in the , Then judge the next number
print("0 1 2 3 4 5 6 7 8 9") # Because all the numbers are 0~9 this 9 Numbers make up , So first output this 9 A digital , That is, the first line in the output sample
for i in range(len(list1)): # Output corresponding times
if i!=9: # Not the last number , Output the number , And end with a space
print(list1[i],end=' ')
else: # There is no space at the end of the last number output , Line break directly
print(list1[i])
The above program gives more detailed comments , For novice Xiaobai's reference . The idea of program design or code implementation is not optimal , You are welcome to correct your mistakes or give better ideas .
I am a rookie who wants to be Kunpeng , Everyone's encouragement is my driving force , Welcome to like collection comments !
边栏推荐
- Detailed explanation of redis' distributed lock principle
- Miscellaneous talk on May 14
- [insert, modify and delete data in the headsong educator data table]
- [the Nine Yang Manual] 2016 Fudan University Applied Statistics real problem + analysis
- 力扣152题乘数最大子数组
- Callback function ----------- callback
- MySQL lock summary (comprehensive and concise + graphic explanation)
- SRC挖掘思路及方法
- canvas基础1 - 画直线(通俗易懂)
- 实验九 输入输出流(节选)
猜你喜欢
[hand tearing code] single case mode and producer / consumer mode
3. Input and output functions (printf, scanf, getchar and putchar)
FAQs and answers to the imitation Niuke technology blog project (I)
甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1
Difference and understanding between detected and non detected anomalies
[dark horse morning post] Shanghai Municipal Bureau of supervision responded that Zhong Xue had a high fever and did not melt; Michael admitted that two batches of pure milk were unqualified; Wechat i
Canvas foundation 1 - draw a straight line (easy to understand)
2022泰迪杯数据挖掘挑战赛C题思路及赛后总结
Differences among fianl, finally, and finalize
.Xmind文件如何上传金山文档共享在线编辑?
随机推荐
Reinforcement learning series (I): basic principles and concepts
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
Leetcode.3 无重复字符的最长子串——超过100%的解法
实验八 异常处理
2022泰迪杯数据挖掘挑战赛C题思路及赛后总结
实验四 数组
Mixlab unbounded community white paper officially released
附加简化版示例数据库到SqlServer数据库实例中
实验七 常用类的使用(修正帖)
C language Getting Started Guide
渗透测试学习与实战阶段分析
[insert, modify and delete data in the headsong educator data table]
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
Strengthen basic learning records
Inaki Ading
优先队列PriorityQueue (大根堆/小根堆/TopK问题)
Matlab opens M file garbled solution
About the parental delegation mechanism and the process of class loading
7-3 构造散列表(PTA程序设计)