华为机试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"])
相关推荐
SmartBrain37 分钟前
基于华为管理理念刨析:三医领域数字化转型战略规划研究报告
人工智能·华为
i建模1 小时前
华为MateBook X Pro 2020款在Ubuntu系统中直接使用原生的杜比全景声效果
linux·ubuntu·华为
funnycoffee1231 小时前
华为CE8865交换机25GE接口使用千兆光模块无法Up故障
华为·transceiver
UnicornDev1 小时前
【HarmonyOS 6】时间管理APP:时光重塑页面布局设计
华为·harmonyos·arkts·鸿蒙·鸿蒙系统
芙莉莲教你写代码1 小时前
Flutter 框架跨平台鸿蒙开发 - 科学实验指南应用
flutter·华为·harmonyos
不爱吃糖的程序媛1 小时前
Flutter鸿蒙PC应用开发实践:从零到运行
flutter·华为·harmonyos
互联网散修1 小时前
鸿蒙应用拼图游戏开发实战:从凹凸碎片生成到精确点击检测
华为·harmonyos
芙莉莲教你写代码2 小时前
Flutter 框架跨平台鸿蒙开发 - 单位换算大师应用
flutter·华为·harmonyos
不爱吃糖的程序媛2 小时前
Flutter应用运行到鸿蒙PC指南
flutter·华为·harmonyos
不爱吃糖的程序媛2 小时前
Flutter OH Engine 构建指导(macOS 版本)
flutter·华为·harmonyos