#TCTM16350. Fix

0
    ID: 2539 传统题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>16350字符串Senior(高级组)CCC 2004中等

Fix

Fix

题目描述

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 1 and 25.A word X is a prefix of word Y if X consists of the first n characters of Y, in order, for some n. That is, the word “cat” has prefixes “c”, “ca”, and “cat”. Similarly, a word X is a suffix of Y if X consists of the last n characters of Y, in order, for some n.

如果一个单词集合满足没有任何单词是其他单词的前缀,则该单词集合是无前缀集合。 如果一个单词集合满足没有任何单词是其他单词的后缀,则该单词集合是无后缀集合。 如果一个单词集合既是无前缀集合也是无后缀集合,就称它是无词缀集合。 一个单词即是自己的前缀也是自己的后缀。 给定 NN 个单词集合,每个集合包含 33 个单词,请你依次判断每个集合是否是无词缀集合。

输入格式

Your input will be 3N+1 lines: the first line will be the number N, and the remaining 3N lines will be the N collections of 3 words each. (That is, lines 2, 3, and 4 compose the first collection, lines 5, 6, and 7 compose the second collection, and so on).

第一行包含整数 NN,表示单词集合数量。

每个单词集合占三行,每行包含一个集合中的单词。

输出格式

Your output will be N lines, each line containing either Yes (if that collection of words is fix-free) or No (if that collection is not fix-free).

每个集合输出一行判断,如果是无词缀集合,则输出 Yes,否则输出 No。

2
abba
aab
bab
a
ab
aa
Yes
No

提示

(暂无提示)

来源

童程童美