华为机试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"])
相关推荐
maaath6 分钟前
【maaath】Flutter for OpenHarmony 跨平台计算器应用开发实践
flutter·华为·harmonyos
以太浮标1 小时前
华为eNSP模拟器综合实验之- MGRE多点GRE隧道详解
运维·网络·网络协议·网络安全·华为·信息与通信
前端不太难5 小时前
鸿蒙PC和App:都在走向 System
华为·状态模式·harmonyos
maaath5 小时前
【maaath】Flutter for OpenHarmony 闹钟时钟应用开发实战
flutter·华为·harmonyos
maaath5 小时前
【maaath】Flutter for OpenHarmony 短信管理应用实战
flutter·华为·harmonyos
程序猿追6 小时前
从零打造一个“跳一跳”:在HarmonyOS模拟器上用Canvas复刻经典
华为·harmonyos
UnicornDev6 小时前
【HarmonyOS 6】底部悬浮导航的迷你栏适配(API23)
华为·harmonyos·arkts·鸿蒙
空中海6 小时前
iOS 静态逆向、IPA 结构与 Mach-O 分析
ios·华为·harmonyos
李李李勃谦6 小时前
鸿蒙PC文件加密工具实战:AES-256-GCM 加密
华为·harmonyos
maaath6 小时前
【maaath】Flutter for OpenHarmony打造跨平台便签备忘录应用
flutter·华为·harmonyos