题解 | #统计人次#

统计人次

https://www.nowcoder.com/practice/325adc585eeb4791a5d92389e5b6c6cc

def main():
    s1 = input()
    try:
        lists = s1.split(' ')
        lists = filter(lambda x: x, lists) #过滤掉空字符
        
        total = 0
        first = -1 #设为-1,避免first==-1判断失效
        i = 0
        for item in lists:
            if item == 'NiuNiu':
                total += 1

                if first == -1:
                    first = i
            
            i += 1

        print(total)
        print(first)
    except Exception as e:
        print(str(e))


if __name__ == '__main__':
    main()

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 13:05
点赞 评论 收藏
分享
06-12 16:23
已编辑
小米_软件开发(准入职员工)
点赞 评论 收藏
分享
07-08 13:48
门头沟学院 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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