#C3005. DNA Sequence Pattern Occurrence

    ID: 46385 Type: Default 1000ms 256MiB

DNA Sequence Pattern Occurrence

DNA Sequence Pattern Occurrence

Given a DNA sequence and a nucleotide pattern, determine the number of times the pattern occurs in the sequence. The sequence contains only the characters \(A\), \(C\), \(G\), and \(T\). You are required to process multiple datasets until a termination dataset is encountered.

Each dataset consists of two integers representing the length of the DNA sequence (\(n\)) and the length of the nucleotide pattern (\(p\)), followed by a DNA sequence and a nucleotide pattern. The termination dataset is indicated by a line where both \(n\) and \(p\) are 0.

Your task is to compute and output the number of occurrences of the nucleotide pattern in the DNA sequence for each dataset (excluding the termination line).

inputFormat

The input contains multiple test cases. Each test case is given in one line in the following format:

n p sequence pattern

where:

  • n is the length of the DNA sequence,
  • p is the length of the nucleotide pattern,
  • sequence is a string composed only of the characters A, C, G, and T,
  • pattern is the nucleotide pattern to search for.

The input is terminated by a line where both n and p are 0.

outputFormat

For each test case (except for the termination line), output a single number on a new line: the number of times the given pattern appears in the DNA sequence.

## sample
10 2 ACGTACGTAC AC
10 3 ACGTACGTAC GTG
0 0
3

0

</p>