当前位置:网站首页>每日一题——PAT乙级1002题
每日一题——PAT乙级1002题
2022-07-07 21:49:00 【InfoQ】
一、PAT (Basic Level) Practice (中文)第1002题
输入格式:
输出格式:
输入样例:
1234567890987654321123456789
输出样例:
yi san wu
transform={'1':'yi','2':'er','3':'san','4':'si','5':'wu','6':'liu','7':'qi','8':'ba','9':'jiu','0':'ling'}
#输入
a=input()
#将输入的数字字符串转换为列表的形式
b=list(a)
#将数字中的每一位求和
c=sum(int(i) for i in b)
#求和结果转为字符串形式,用于计算长度
d=str(c)
#标记位,用来判断for循环的最后一个
flag=0
for j in d:
flag=flag+1
#如果为for循环的最后一位,则不输出空格
if flag==len(d):
#print默认的end为end='\n',先根据情况将其修改
print(transform[j],end='')
else:
print(transform[j],end=' ')
transform={'1':'yi','2':'er','3':'san','4':'si','5':'wu','6':'liu','7':'qi','8':'ba','9':'jiu','0':'ling'}
a=input()
print("input输入的类型:",type(a))
b=list(a)
print("转发化为列表的b为:",b)
#c=sum(int(i) for i in b)
sum=0
for i in a:
s=int(i)
sum=sum+s
print('sum的数据类型:',type(sum)," 结果: ",sum)
d=str(sum)
print("转化为字符串形式的sum"," 类型:",type(d)," 字符串形式的数:",d," 他的长度:",len(d))
flag=0
for j in d:
flag=flag+1
if flag==len(d):
print(transform[j],end='')
else:
print(transform[j],end=' ')
边栏推荐
- 7-51 combination of two ordered linked list sequences
- How to judge whether the input content is "number"
- Select sort (illustration +c code)
- Interview questions: how to test app performance?
- Revit secondary development - operation family documents
- 行测-图形推理-9-线条问题类
- Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~
- LeetCode144. Preorder traversal of binary tree
- LeetCode206. Reverse linked list [double pointer and recursion]
- ADC采样率(HZ)是什么怎么计算
猜你喜欢
Microbial Health Network, How to restore Microbial Communities
Visual design form QT designer design gui single form program
Gazebo import the mapping model created by blender
Ni9185 and ni9234 hardware settings in Ni Max
Visual studio 2019 installation
LeetCode707. Design linked list
Leetcode206. Reverse linked list
ASP. Net core introduction V
The author of LinkedList said he didn't use LinkedList himself
行测-图形推理-7-相异图形类
随机推荐
Understand the session, cookie and token at one time, and the interview questions are all finalized
Redis cluster installation
Debezium series: set role statement supporting mysql8
Unity and webgl love each other
There is another problem just online... Warm
行測-圖形推理-4-字母類
Leetcode1984. Minimum difference in student scores
LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]
Debezium series: binlogreader for source code reading
Unity 动态合并网格纹理
Loki, the "open source star picking program", realizes the efficient management of harbor logs
Debezium系列之:源码阅读之SnapshotReader
Revit secondary development - link file collision detection
Sword finger offer 55 - I. depth of binary tree
Nx10.0 installation tutorial
Ni9185 and ni9234 hardware settings in Ni Max
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xf9 in position 56: illegal multibyte sequence
行测-图形推理-4-字母类
Build an "immune" barrier in the cloud to prepare your data
Line test - graphic reasoning - 2 - black and white lattice class