题解 | #统计字符#

统计字符

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

s = input()

dicts = {'words':0 , 'empty':0 , 'number':0 , 'others':0}

for i in s:
    if ord('a') <= ord(i) <= ord('z'):
        dicts['words'] += 1
    elif ord('A') <= ord(i) <= ord('Z'):
        dicts['words'] += 1
    elif ord('0') <= ord(i) <= ord('9'):
        dicts['number'] += 1
    elif i == ' ':
        dicts['empty'] += 1
    else:
        dicts['others'] += 1

for key, value in dicts.items():
    print(value)

全部评论

相关推荐

03-25 19:00
东北大学 Java
程序员牛肉:太好了,是聊天记录。不得不信了。 当个乐子看就好,不要散播焦虑
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务