CF988B.Substrings Sort
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n 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 a is a substring of string b if it is possible to choose several consecutive letters in b in such a way that they form a. 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".
给你 n 个字符串,每个字符串均由小写英文字母组成。请重新排列(重排序)这些字符串,使得对每个字符串而言,排在其前面的所有字符串都是它的子串。
若字符串 a 可通过选取字符串 b 中若干连续的字母而构成,则称 a 是 b 的子串。例如,字符串 "for" 是字符串 "codeforces"、"for" 和 "therefore" 的子串,但不是字符串 "four"、"fofo" 和 "rof" 的子串。
输入格式
The first line contains an integer n (1≤n≤100) — the number of strings.
The next n lines contain the given strings. The number of letters in each string is from 1 to 100, inclusive. Each string consists of lowercase English letters.
Some strings might be equal.
第一行包含一个整数 n(1≤n≤100)—— 字符串的数量。
接下来的 n 行包含给定的字符串。每个字符串的字母数量在 1 到 100 之间(含端点)。每个字符串均由小写英文字母组成。
某些字符串可能相等。
输出格式
If it is impossible to reorder n given strings in required order, print "NO" (without quotes).
Otherwise print "YES" (without quotes) and n given strings in required order.
如果无法将给定的 n 个字符串重新排列成所要求的顺序,则输出 "NO"(不带引号)。
否则,输出 "YES"(不带引号),并在下一行输出按所要求顺序排列的 n 个给定字符串。
输入输出样例
输入#1
5 a aba abacaba ba aba
输出#1
YES a ba aba aba abacaba
输入#2
5 a abacaba ba aba abab
输出#2
NO
输入#3
3 qwerty qwerty qwerty
输出#3
YES qwerty qwerty qwerty
说明/提示
In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".
在第二个例子中,您不能重新排列这些字符串,因为字符串 “abab” 不是字符串 “abacaba” 的子串。
输入解题思路,AI测评打分。不知道怎么写?