华为机试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"])
相关推荐
鸿蒙开发工程师—阿辉10 小时前
HarmonyOS Next元服务网络请求封装实践
网络·华为·typescript·harmonyos·元服务
MardaWang17 小时前
HarmonyOS 应用程序包结构 (编译态)
华为·harmonyos
zhgjx_chen18 小时前
华为:Wireshark的OSPF抓包分析过程
测试工具·华为·wireshark
枫叶丹419 小时前
【HarmonyOS Next之旅】DevEco Studio使用指南(一)
华为·harmonyos·deveco studio·harmonyos next
23zhgjx-zgx1 天前
OSPF网络类型:NBMA与P2MP
网络·华为·智能路由器·ensp
23zhgjx-NanKon1 天前
华为eNSP:配置单区域OSPF
华为
zhgjx-dengkewen1 天前
华为eNSP:实验 配置P2P网络类型
网络·网络协议·华为·p2p
轻口味1 天前
【每日学点HarmonyOS Next知识】对话框回调问题、输入区域最大行数、web自定义节点、icon图标库、软键盘开关
前端·pytorch·华为·harmonyos·harmonyosnext
东林知识库1 天前
鸿蒙NEXT开发-应用/元服务签名
华为·harmonyos
m0_748236832 天前
HarmonyOS Next 实现登录注册页面(ARKTS) 并使用Springboot作为后端提供接口
spring boot·华为·harmonyos