Canadian Computing Competition: 2004 Stage 1, Senior #1
A collection of words is prefix-free if no word is a prefix of any other word. A collection of words is suffix-free if no word is a suffix of any other word. A collection of words is fix-free if it is both prefix-free and suffix-free.
For this problem, a word is a sequence of lower-case letters of length between cat
has prefixes c
, ca
, and cat
. Similarly, a word
Your input will be Yes
(if that collection of words is fix-free) or No
(if that collection is not fix-free).
Sample Input
2
abba
aab
bab
a
ab
aa
Sample Output
Yes
No
Comments
this stupud question had to put "yes" and "no" in capitals so i wasted like 20 minutes trying to figure otu the error, only to find that i did not use capitals.
I do not see why, in the example output, that the first collection is fix-free. The first two words in the input have the letter "a" as a common prefix, and the last two words in the first collection have the letter "b" as a common suffix. Can anyone help explain to me why my thinking is incorrect?
The common fixes have to be fellow words in the list.
Are the three words in a set all distinct?
I don't think the problem statement guarantees them to be distinct.
I got different results on ideone.com and dmoj.ca, using same code. Any hint?
I'm guessing you didn't initialize a variable which may cause it to initialize a random integer/string/char