题解 | #统计字符#
统计字符
http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
while True:
try:
raw_str = input()
res_dic = {"Char": 0, "Space": 0, "Digit": 0, "Other": 0}
for c in raw_str:
if c.isalpha():
res_dic["Char"] += 1
elif c.isspace():
res_dic["Space"] += 1
elif c.isdigit():
res_dic["Digit"] += 1
else:
res_dic["Other"] += 1
for k,v in res_dic.items():
print(v)
except:
break
查看23道真题和解析