当前位置:网站首页>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))
边栏推荐
- 7-2 Finnish wooden chess structure Sorting
- 基金的投资交易与结算
- 本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
- Hack the box:routerspace
- R and RGL draw 3D knots
- DOM parsing of XML file case code sentence by sentence analysis
- R language drawing ggplot2 seasonal graph
- R 语言 Kolmogorov-Smirnov 检验 2 个样本是否遵循相同的分布。
- QT -- communication protocol
- Unity UI shadow component
猜你喜欢

Kubelet garbage collection (exiting containers and unused images) source code analysis

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

Safety training is the greatest benefit for employees! 2022 induction safety training for new employees

What is a consistent hash? What scenarios can it be applied to?

What is EC blower fan?

Modifying MySQL port number under Linux

The practice of event driven architecture in vivo content platform

ES6 use of return in arrow function

Design and implementation of spark offline development framework

Mysql57 zip file installation
随机推荐
7-1 understand everything
kubernetes部署thanos ruler的发送重复告警的一个隐秘的坑
The practice of event driven architecture in vivo content platform
Cloud native (to be updated)
Hack the box:routerspace
Can okcc call centers work without computers?
MySQL installation steps - how to create a virtual machine under Linux (1)
R language hitters data analysis
Source code analysis of kubernetes' process of deleting pod
linux下修改mysql端口号
R 语言绘制 动画气泡图
Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
分析 NFT 项目的 5 个指标
R 语言 Kolmogorov-Smirnov 检验 2 个样本是否遵循相同的分布。
Drawing animated bubble chart with R language
Mysql8.0和Mysql5.0访问jdbc连接
Open62541 import nodeset file directly
Uninstall and reinstall the latest version of MySQL database. The test is valid
Install haproxy
Huawei cloud computing physical node cna installation tutorial