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

计算某字符出现次数

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

def count_char_occurrences(string, char):
    # 将字符串和字符都转换为小写,以便不区分大小写
    string = string.lower()
    char = char.lower()
    
    # 使用 count() 方法计算字符在字符串中出现的次数,并返回结果
    return string.count(char)

while True:
    try:
        # 逐行读取输入
        input_string = input().strip()
        char_to_count = input().strip()

        # 调用函数计算字符在字符串中出现的次数,并输出结果
        print(count_char_occurrences(input_string, char_to_count))
    except EOFError:
        break


全部评论

相关推荐

牛客小菜鸡66:boss里面,招人的叫老板,找工作的叫牛人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务