华为机试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 小时前
MateChat 进阶实战:打造零后端、隐私安全的“端侧记忆”智能体
前端·华为·ai·华为云·状态模式
是Dream呀13 小时前
昇腾实战|算子模板库Catlass与CANN生态适配
开发语言·人工智能·python·华为
RisunJan14 小时前
【HarmonyOs】鸿蒙应用开发方向选择
华为·harmonyos
无限码力14 小时前
【全网首发】2025华为OD机试双机位C卷(机考全真题库)含考点说明(华为OD上机考试双机位C卷)
华为od·华为od机考·华为od机试·华为od机试双机位c卷·华为od机考双机位c卷·华为od上机考试双机位c卷
RisunJan17 小时前
HarmonyOS 系统概述
华为·harmonyos
泓博17 小时前
鸿蒙网络请求流式返回实现方法
华为·harmonyos
北方的流星20 小时前
华为AC+AP旁挂式三层无线局域网的配置案例
运维·网络·经验分享·华为
lichong95120 小时前
harmonyos 大屏设备怎么弹出 u 盘
前端·macos·华为·typescript·android studio·harmonyos·大前端
diygwcom21 小时前
UniApp 鸿蒙NEXT蓝牙连接及数据写入
华为·uni-app·harmonyos