当前位置:网站首页>PAT乙级1002:写出这个数
PAT乙级1002:写出这个数
2022-07-17 05:04:00 【哆啦k梦0219】
题目描述:
读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:
每个测试输入包含 1 个测试用例,即给出自然数 n 的值。这里保证 n 小于 10100。
输出格式:
在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:
1234567890987654321123456789
输出样例:
yi san wu
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
考虑到C/C++代码量比较大,还要用到switch—case结构,所以这里本人采用Python来写……代码量少很多。
其中用到了Python中‘字典’这个数据类型 ,值得记录一下,代码如下:
def main():
sum=0
dict={'1':"yi",'2':'er','3':'san','4':'si','5':'wu','6':'liu','7':'qi','8':'ba','9':'jiu','0':'ling'}
n=input()
for i in range(len(n)):
sum=sum+int(n[i])
string=str(sum)
for i in range(len(string)):
if i<=len(string)-2:
print(dict[string[i]],end=' ')
else:
print(dict[string[i]])
main()边栏推荐
- Simply and quickly establish a pytorch environment yolov5 target detection model to run (super simple)
- Desensitization field example
- 读论文《SNUNet-CD: A Densely Connected Siamese Network for Change Detection of VHR Images》
- Encryption and decryption
- 02_電影推薦(ContentBased)_用戶畫像
- String string special interception processing according to symbols
- . SH scripting
- 【C语言—零基础第八课】循环结构与break continue
- 【C语言—零基础第十一课】旋转大转盘之指针
- Cve-2021-44228 log4j reproduction and principle
猜你喜欢

Learn about scheduled tasks in one article

用户的管理-限制

MySQL takes the union of two query conditions and then queries

Cve-2017-12635 CouchDB vertical privilege bypass vulnerability recurrence

CVE-2019-14234 Django JSONField SQL注入漏洞

Implementation idea of log adding to database

Sleuth getting started

决策树原理和案例应用-泰坦尼克号生存预测

Asynchronous data SMS verification code

卷积神经网络
随机推荐
用户管理-分页
第十届泰迪杯数据挖掘挑战赛A题害虫识别YOLOv5模型代码(已跑通,原创作品,持续更新)
学习C语言第三天
02_电影推荐(ContentBased)_用户画像
C语言 带你 手撕 通讯录
Hire the server, and the pytorch environment training yolov5 model tutorial deployed on pycharm professional edition. Server environment installation library file:
MySQL fuzzy matching 1, 11111 similar string problems
MySQL takes the union of two query conditions and then queries
God rewards hard work, keep loving
Cve-2020-10199 recurrence of nexus repository manager3 remote command execution vulnerability
String string special interception processing according to symbols
用户的管理-限制
【C】张梁计算器
机器学习之PCA特征降维+案例实践
Learn about the configuration center
One article to understand Zipkin
Actual cases of data analysis and data mining local house price prediction (716):
机器学习之特征提取(类别特征进行数值化、离散化、文本特征进行数值化)
Harmonyos入门
学习C语言的第四天