You are given nn strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String aa is a substring of string bb if it is possible to choose several consecutiveletters in bb in such a way that they form aa. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof".
Input
The first line contains an integer nn (1≤n≤1001≤n≤100) — the number of strings.
The next nn lines contain the given strings. The number of letters in each string is from 11 to 100100, inclusive. Each string consists of lowercase English letters.
Some strings might be equal.
Output
If it is impossible to reorder nn given strings in require
Substrings Sort
最新推荐文章于 2021-08-12 16:19:39 发布
题目要求重新排列字符串,使得每个字符串前面的字符串都是它的子串。可以利用strstr函数来判断子串关系。如果能完成排列则输出'YES'及排列后的字符串,否则输出'NO'。
摘要由CSDN通过智能技术生成