#K52227. Counting Pattern Occurrences
Counting Pattern Occurrences
Counting Pattern Occurrences
Given a text document and a word pattern, count how many times the pattern appears as a complete word in the document regardless of its case.
Note: The comparison is case-insensitive. Only matches as whole words are considered. For instance, when matching the pattern \(pattern\)
against the word Pattern
or PATTERN
, they are counted as valid occurrences. However, substrings within longer words should not be counted.
The input is provided via standard input (stdin) and the output should be printed to standard output (stdout).
Input Format: The input consists of multiple lines. All lines except the last one belong to the document text, and the last line is the pattern you need to search for.
Output Format: Output a single integer that represents the number of occurrences of the pattern as a whole word in the document.
inputFormat
The input is read from standard input. The document may span multiple lines. The last line of the input is the pattern, and all preceding lines form the document. For example:
Line 1: Pattern recognition is a branch of machine learning. Line 2: PATTERN recognition systems are in many applications. Line 3: pattern
Here, lines 1 and 2 form the document, and line 3 is the pattern.
outputFormat
Output a single integer number representing the count of occurrences of the given pattern as a whole word, using case-insensitive matching.
## samplePattern recognition is a branch of machine learning.
pattern
1