列表

详情


NC215138. AlgorithmCourse

描述

Kotori has just learnt the Knuth-Morris-Pratt algorithm in the algorithm course and would like to give the following problem a try:

Find the total number of occurrence of the strings "cat" and "dog" in a given string s.

As Kotori is not familiar with the KMP algorithm, she turns to you for help. Can you help Kotori solve this problem?

输入描述

There is only one test case in each test file.

The first and only line contains a string s () which only contains lower-cased English letters.

输出描述

Output one line containing one integer indicating the total number of occurrence of "cat" and "dog" in the string.

示例1

输入:

catcatcatdogggy

输出:

4

示例2

输入:

docadosfascat

输出:

1

示例3

输入:

icpcnanjing

输出:

0

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Python3(3.9) 解法, 执行用时: 18ms, 内存消耗: 2804K, 提交时间: 2020-12-20 14:38:37

a=input()
print(a.count('dog')+a.count('cat'))

上一题