## CCC '04 S1 - Fix

View as PDF

Points: 5
Time limit: 2.0s
Memory limit: 256M

Problem type
##### 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 and . A word is a prefix of word if consists of the first characters of , in order, for some . That is, the word cat has prefixes c, ca, and cat. Similarly, a word is a suffix of if consists of the last characters of , in order, for some .

Your input will be lines: the first line will be the number , and the remaining lines will be the collections of words each. (That is, lines , , and compose the first collection, lines , , and compose the second collection, and so on). Your output will be lines, each line containing either 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

• commented on Dec. 31, 2019, 5:35 a.m.

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?

• commented on Dec. 31, 2019, 4:36 p.m.

The common fixes have to be fellow words in the list.

• commented on March 23, 2019, 1:38 p.m.

Are the three words in a set all distinct?

• commented on March 23, 2019, 5:21 p.m. edited

I don't think the problem statement guarantees them to be distinct.

• commented on Feb. 14, 2017, 3:19 p.m.

I got different results on ideone.com and dmoj.ca, using same code. Any hint?

• commented on March 24, 2018, 3:26 p.m.

I'm guessing you didn't initialize a variable which may cause it to initialize a random integer/string/char

• commented on Feb. 11, 2017, 4:44 p.m.

.