题解 | #统计字符#

统计字符

https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5

s=list(input())
lenth_s=len(s)
num_num=0
num_f=0
num_y=0
num_zhon=0
num_k=0
for each in s:
    if '0'<= each <= '9':
        num_num+=1
    if each==' ':
        num_k+=1
    if 'a' <= each <= 'z' or 'A' <= each <= 'Z':
        num_y+=1
    if '9' < each < 'A' or ' '< each < '0' or 'Z' < each < 'a' or each > 'z':
        num_f+=1
num_zhon=lenth_s-(num_f+num_k+num_y+num_num)
print(num_y+num_zhon)
print(num_k)
print(num_num)
print(num_f)

主要是记住ASC码表:

https://blog.csdn.net/lj19990824/article/details/120162269?ops_request_misc=&request_id=&biz_id=102&utm_term=ascii%E7%A0%81%E5%AF%B9%E7%85%A7%E8%A1%A8&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-2-120162269.142^v74^pc_search_v2,201^v4^add_ask,239^v2^insert_chatgpt&spm=1018.2226.3001.4187

全部评论

相关推荐

三年之期已到我的offer快到碗里来:9硕都比不上9本
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务