华为机试HJ40统计字符

华为机试HJ40统计字符

题目:

想法:

统计上述题目中的四种字符的个数存入字典中,按指定顺序进行输出

复制代码
input_str = input()

str_dict = {"alpha": 0, "space": 0, "number": 0, "others": 0}

for i in input_str:
    if i.isalpha():
        str_dict["alpha"] += 1
    elif i == " ":
        str_dict["space"] += 1
    elif i.isdigit():
        str_dict["number"] += 1
    else:
        str_dict["others"] += 1

print(str_dict["alpha"])
print(str_dict["space"])
print(str_dict["number"])
print(str_dict["others"])
相关推荐
江拥羡橙4 小时前
【目录-单选】鸿蒙HarmonyOS开发者基础
前端·ui·华为·typescript·harmonyos
爱笑的眼睛114 小时前
HarmonyOS应用开发:深入ArkUI声明式开发范式与最佳实践
华为·harmonyos
云水木石5 小时前
开源鸿蒙+龙芯CPU,能擦出怎样的火花?
华为·开源·harmonyos
江拥羡橙10 小时前
【目录-多选】鸿蒙HarmonyOS开发者基础
前端·ui·华为·typescript·harmonyos
爱笑的眼睛1116 小时前
HarmonyOS Stage 模型深度解析:构建现代化、高性能应用
华为·harmonyos
安卓开发者20 小时前
鸿蒙NEXT自定义能力详解:从基础使用到高级技巧
华为·harmonyos
特立独行的猫a21 小时前
HarmonyOS 鸿蒙系统自带的 SymbolGlyph 图标组件详解
华为·harmonyos·图标·symbolglyph
2501_9197490321 小时前
鸿蒙:使用EventHub实现多模块之间的通信
华为·harmonyos
2501_919749031 天前
鸿蒙:使用Emitter进行线程间通信
华为·harmonyos
SuperHeroWu71 天前
【HarmonyOS 6】仿AI唤起屏幕边缘流光特效
华为·harmonyos·特效·鸿蒙6.0·流光·ai唤起·屏幕边缘