#C4487. DNA Pattern Count
DNA Pattern Count
DNA Pattern Count
You are given a DNA fragment represented as a string, an integer L denoting the length of the pattern to search for, and a target motif (pattern) as another string. Your task is to count how many times the motif appears in the DNA fragment. Note that if the pattern is an empty string (i.e. L = 0), then it is considered to occur between every character (including before the first character and after the last one), resulting in \(n+1\) occurrences for a DNA fragment of length \(n\).
Input Format: The input will be provided via standard input (stdin) in three lines:
- The first line contains the DNA fragment, a string consisting of characters such as A, C, G, T.
- The second line contains an integer \(L\) representing the length of the pattern.
- The third line contains the pattern string which has exactly \(L\) characters (it can be empty if \(L = 0\)).
Output Format: A single integer should be printed to standard output (stdout), representing the count of occurrences of the pattern in the DNA fragment.
Example:
Input: ACGTACGTACGT 3 ACG</p>Output: 3
inputFormat
The input contains three lines:
- DNA fragment: A string of uppercase letters (e.g. A, C, G, T).
- Pattern Length: An integer \(L\) that indicates the length of the pattern to search for.
- Pattern: A string of exactly \(L\) characters (or empty if \(L = 0\)).
outputFormat
Print a single integer to stdout representing the number of times the pattern occurs in the given DNA sequence. When the pattern is empty, output should be \(n + 1\) where \(n\) is the length of the DNA fragment.
## sampleACGTACGTACGT
3
ACG
3