Monday, May 5, 2014

A Needle in the Haystack

Problem

 The program has to detect all occurences of the needle in the haystack. It should take the needle and the haystack as input, and output the positions of each occurence, as shown below.

Input
The input consists of a number of test cases. Each test case is composed of three lines, containing:

the length of the needle,
the needle itself,
the haystack.

Output
For each test case your program should output all positions of the needle's occurences within the haystack.

Example:

Input :
2
na
banananobano

output:
2
4

Solution

Hint:Use KMP

References

Reactions:

0 comments:

Post a Comment