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 consecutive letters 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 required order, print "NO" (without quotes).

Otherwise print "YES" (without quotes) and nn given strings in required order.

Examples
input

Copy
5
a
aba
abacaba
ba
aba
output

Copy
YES
a
ba
aba
aba
abacaba
input

Copy
5
a
abacaba
ba
aba
abab
output

Copy
NO
input

Copy
3
qwerty
qwerty
qwerty
output

Copy
YES
qwerty
qwerty
qwerty
Note

In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".

 #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
typedef long long LL;
int n;
string a[];
int cmp(string a, string b) {
return a.size() < b.size();
}
int main() {
scanf("%d", &n);
for (int i = ; i < n ; i++) cin >> a[i];
sort(a, a + n, cmp);
int num=;
for (int i = ; i < n ; i++) {
if (a[i].find(a[i-]) != string::npos) num++;
}
if (num!=n-) printf("NO\n");
else {
printf("YES\n");
for (int i = ; i < n ; i++ )
cout << a[i] << endl;
}
return ;
}

Substrings Sort string 基本操作的更多相关文章

  1. Codeforces Round #486 (Div. 3)-B. Substrings Sort

    B. Substrings Sort time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. G面经prepare: Sort String Based On Another

    Given a sorting order string, sort the input string based on the given sorting order string. Ex sort ...

  3. 791. Custom Sort String - LeetCode

    Question 791. Custom Sort String Solution 题目大意:给你字符的顺序,让你排序另一个字符串. 思路: 输入参数如下: S = "cba" T ...

  4. Substrings Sort

    You are given nn strings. Each string consists of lowercase English letters. Rearrange (reorder) the ...

  5. B - Substrings Sort

    Problem description You are given nn strings. Each string consists of lowercase English letters. Rea ...

  6. [LeetCode] Custom Sort String 自定义排序的字符串

    S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sort ...

  7. 牛客第三场多校 E Sort String

    链接:https://www.nowcoder.com/acm/contest/141/E来源:牛客网 Eddy likes to play with string which is a sequen ...

  8. 791. Custom Sort String

    S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sort ...

  9. 牛客网暑期ACM多校训练营(第三场) E Sort String 哈希处理字符串(模板)

    链接:https://www.nowcoder.com/acm/contest/141/E来源:牛客网 Eddy likes to play with string which is a sequen ...

随机推荐

  1. 多线程编程之Apue3rd_Chapter15.10之posix信号量

    看了APUE的chapter15,只重点看了15.10,学习了posix信号量.Posix信号量比起xsi信号量的优点是性能更好,在Linux3.2.0平台上性能提升很大.其中命名信号量使用方法如下. ...

  2. vue---day03

    1. Vue的生命周期 - 创建和销毁的时候可以做一些我们自己的事情 - beforeCreated - created - beforeMount - mounted - beforeUpdate ...

  3. iScroll实现下拉刷新上拉加载

    前言 初学iscroll这个控件,给我的一个感觉还是蛮不错的. 什么是iScroll:是目前最成熟的自定义滚动解决方案之一,在移动端和PC有很好的兼容性.iScroll官方提供了5个不同的版本 isc ...

  4. Kubernetes-apiserver

    Kubernetes API服务器为API对象验证和配置数据,这些对象包含Pod.Service.ReplicationController等等.API Server提供REST操作以及前端到集群的共 ...

  5. (数据科学学习手札19)R中基本统计分析技巧总结

    在获取数据,并且完成数据的清洗之后,首要的事就是对整个数据集进行探索性的研究,这个过程中会利用到各种描述性统计量和推断性统计量来初探变量间和变量内部的基本关系,本篇笔者便基于R,对一些常用的数据探索方 ...

  6. 8.Mongodb备份与恢复

    1.备份 语法 mongodump -h dbhost -d dbname -o dbdirectory -h:服务器地址,也可以指定端口号 -d:需要备份的数据库名称 -o:备份的数据存放位置,此目 ...

  7. C#窗口抖动

    用过QQ的窗口抖动功能吧.是不是觉得很神奇?很有意思?其实,仔细想想,使用的原理还是挺简单的:让窗口的位置不断快速地发生变化. 说出了原理,是不是一下恍然大悟?顿时理解了.我以前也想过如何实现这个功能 ...

  8. lua优化

    前言 Lua是一门以其性能著称的脚本语言,被广泛应用在很多方面,尤其是游戏.像<魔兽世界>的插件,手机游戏<大掌门><神曲><迷失之地>等都是用Lua来 ...

  9. TensorFlow 同时调用多个预训练好的模型

    在某些任务中,我们需要针对不同的情况训练多个不同的神经网络模型,这时候,在测试阶段,我们就需要调用多个预训练好的模型分别来进行预测. 调用单个预训练好的模型请点击此处 弄明白了如何调用单个模型,其实调 ...

  10. xml解析标签

    //获取两个标签之间的值 private static string GetStr(string message, string strStart, string strEnd) { ; ; star ...