华为机试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"])
相关推荐
讯方洋哥12 小时前
HarmonyOS App开发——鸿蒙ArkTS基于首选项引导页的集成和应用
华为·harmonyos
总有刁民想爱朕ha20 小时前
haihong Os 鸿蒙开源版开发一个pc版软件应用(1)
华为·开源·harmonyos
路-buan21 小时前
华为eNSP:三种配置防火墙的方式
华为
爱网络爱Linux1 天前
华为 HCIA-Datacom考试版本升级 V2.0!2026年7月起考新版
华为·hcie·hcip·h12-811·华为数通认证·hcia datacom·微信公众号:厦门微思网络
Swift社区1 天前
鸿蒙 App 的数据流设计
华为·harmonyos
Swift社区1 天前
Flutter 迁移鸿蒙 ArkUI 的真实成本
flutter·华为·harmonyos
GitCode官方1 天前
AtomGit 携手开源鸿蒙,推动智能终端操作系统生态繁荣
华为·开源·harmonyos·atomgit
池央2 天前
在鸿蒙上跑 AI Agent:JiuwenClaw-on-OpenHarmony 完整实战
人工智能·华为·harmonyos
互联网散修2 天前
零基础鸿蒙应用开发第五节:基础数据类型与对象类型转换
华为·harmonyos·鸿蒙应用开发入门教程
互联网散修2 天前
零基础鸿蒙应用开发第六节:复杂数据类型入门 —— 数组、元组与枚举
华为·log4j·harmonyos