当前位置:网站首页>HJ字符个数统计
HJ字符个数统计
2022-06-28 07:36:00 【有勇气的牛排】
知识点:字符串、哈希
描述
编写一个函数,计算字符串中含有的不同字符的个数。字符在 ASCII 码范围内(0~127,包括0和127),换行表示结束符,不算在字符里。不在范围内的不作统计。多个相同的字符只计算一次
例如,对于字符串 abaca 而言,有 a、b、c 三种不同的字符,因此输出3。
数据范围:1≤n≤500
输入描述:
输入一行没有空格的字符串。
输出描述:
输出 输入字符串 中范围在(0~127,包括0和127)字符的种数。
示例1
输入:abc
输出:3
输入:aaa
输出:1
牛客HJ python3
# 方法一 28ms
str_list = list(set(input())) # 输入、去重、转列表
# 开始计数
conut = 0
for i in str_list:
if 0 <= ord(i) <= 127: # 判断ASCII码 是否符合要求
conut += 1
print(conut)
# 方法二 30ms
str_list = list(set(input())) # 输入、去重、转列表
# 开始计数
res_list = []
for i in str_list:
if 0 <= ord(i) <= 127: # 判断ASCII码 是否符合要求
res_list.append(i)
print(len(res_list))
边栏推荐
- QT -- 通讯协议
- Code submission specification
- Install haproxy
- Kubernetes deploys a secret pit where thanos ruler sends repeated alarms
- goland IDE和delve调试位于kubernetes集群中的go程序
- Flutter realizes the function of "shake"
- Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
- NDK 交叉编译
- R 语言 Hitters 数据分析
- ES6 use of return in arrow function
猜你喜欢

本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献

Redis one master multi slave cluster setup

Redis implements distributed locks

open62541直接导入NodeSet文件

PLC -- 笔记

MySQL installation steps - how to create a virtual machine under Linux (1)

Construction and exploration of vivo database and storage platform

Uninstall and reinstall the latest version of MySQL database. The test is valid

Jinshan cloud team shared | 5000 words to understand how Presto matches with alluxio

Modifying MySQL port number under Linux
随机推荐
Analyze 5 indicators of NFT project
MySQL installation steps - installing MySQL on Linux (3)
Optimization steps of SQL statements (II) -- MySQL statement optimization
ABAP 技能树
Resizing node of rediscluster cluster cluster mode
es6箭头函数中return的用法
Leetcode+ 66 - 70 high precision, two sub topics
Design and practice of vivo sensitive word matching system
Recommended system series (Lecture 5): Optimization Practice of sorting model
大型项目中的Commit Message规范化控制实现
MMR rearrangement (similarity is calculated by editing distance and repeatability)
Is it reliable to register and open an account for stock speculation? Is it safe?
kubernetes部署thanos ruler的发送重复告警的一个隐秘的坑
linux下修改mysql端口号
Evaluation of inverse Polish expression < difficulty coefficient >
Practice and exploration of vivo live broadcast application technology
ES6 use of return in arrow function
Leetcode+ 51 - 55 retrospective and dynamic planning topics
What should I do if the version is incompatible with the jar package conflict?
股票炒股注册开户靠谱吗?安全吗?