题解 | #计算某字符出现次数#

计算某字符出现次数

https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1

# upper()把所有字母都变成大写
# lower()把所有字母都变成小写
# Counter()计数器,统计列表中的类型,并以字典的形式进行存储
# strip()会把换行、回车、制表符、空格全移除,并返回移除字符串头尾指定的字符生成的新字符串

# 刚开始习惯使用input()
# a=input().lower()
# b=input().lower()
# count = 0
# for i in a:
#     if i == b:
#         count+=1
# print(count)

# 看题解里多数是用的sys.stdin.readline()
import sys
from collections import Counter
a = sys.stdin.readline().upper()
# 获取第二个输入的时候一定要有strip()
b = sys.stdin.readline().upper().strip() 
n = Counter(a)
print(n[b])

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务