其他分享
首页 > 其他分享> > 牛客华为机试HJ40

牛客华为机试HJ40

作者:互联网

原题传送门

1. 题目描述

2. Solution 1

import sys

if sys.platform != "linux":
    file_in = open("input/HJ40.txt")
    sys.stdin = file_in

for line in sys.stdin:
    result = dict(letters=0, spaces=0, digits=0, other=0)
    s = line.strip()
    for c in s:
        if c.isalpha():
            result['letters'] += 1
        elif c == ' ':
            result['spaces'] += 1
        elif c.isdigit():
            result['digits'] += 1
        else:
            result['other'] += 1
    for v in result.values():
        print(v)

标签:elif,letters,sys,牛客,HJ40,spaces,result,file,机试
来源: https://www.cnblogs.com/junstat/p/16168271.html