华为机试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"])
相关推荐
哪 吒1 小时前
2025B卷 - 华为OD机试七日集训第5期 - 按算法分类,由易到难,循序渐进,玩转OD(Python/JS/C/C++)
python·算法·华为od·华为od机试·2025b卷
网络小白不怕黑7 小时前
华为设备 QoS 流分类与流标记深度解析及实验脚本
网络·华为
网络小白不怕黑7 小时前
华为交换机堆叠与集群技术深度解析附带脚本
网络·华为
幽蓝计划19 小时前
HarmonyOS NEXT仓颉开发语言实战案例:动态广场
华为·harmonyos
幽蓝计划1 天前
HarmonyOS NEXT仓颉开发语言实战案例:电影App
华为·harmonyos
HMS Core1 天前
HarmonyOS免密认证方案 助力应用登录安全升级
安全·华为·harmonyos
伍哥的传说1 天前
鸿蒙系统(HarmonyOS)应用开发之手势锁屏密码锁(PatternLock)
前端·华为·前端框架·harmonyos·鸿蒙
funnycoffee1231 天前
Huawei 6730 Switch software upgrade example版本升级
java·前端·华为
制造数字化方案研究院1 天前
59页|PPT|华为集成服务交付ISD业务变革总体方案:业务规则、流程、IT、组织及度量“四位一体”的管理体系
运维·华为
博睿谷IT99_1 天前
华为物联网认证:开启万物互联的钥匙
物联网·华为·华为认证·职业规划