UVa 10679 - I Love Strings!!

10679 - I love Strings!!!

 * http://acm.uva.es/p/v106/10679.html

Summary
Given a text string and a set of patterns as input, determine patterns that match the text.

Explanation
This problem is almost exactly stated as the Aho Corasick algorithm. The Aho Corasick algorithm constructs an augmented trie so that all patterns can be matched in a single scan of the text. See the reference below for quality reference notes.

Gotchas

 * Patterns may be repeated
 * Make sure you handle the case of input text as all X, and the patterns as all X of varying sizes with reasonable speed.

Input
1 ushers 4 he she his hers

Output
y y n y