题解 | #统计字符#

统计字符

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)

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务