B. Substrings Sort
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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".

被HACK掉了。。。只能说数据太水了。。。发现自己的程序问题还这么大,还是太菜了。

本题题意就是是否可以把所给的N个序列摆放成上面的序列是下面序列的子序列

开始想了半天。。。怎么找啊。。。这™序列这么多,要我一个一个比?后来发现,你只需要按照从小到大的序列长度排序就好了啊。。。然后从下往上,两个判断是否上面的那么个序列是下面序列的子序列。o(n)操作嘛,小case.

被HACK掉原因就是我匹配那里写错了

正确写匹配姿势:

  for (int i=; i<=word[p].len-word[p-].len; i++)//每个头位置的指针
{
flag=;
pi=i;//检查在I为头的情况下的是否匹配的指针
for(int j=; j<word[p-].len;j++)
{
if(word[p].sub[pi]!=word[p-].sub[j])
{
flag=;//如果有不同
break;
}
else
{
pi++;//继续匹配
continue;
}
}
if (flag==)break;
}

emmmmm最后AC代码

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct Node
{
char sub[];
int len;
} word[];
bool cmp(Node x,Node y)
{
return x.len<y.len;//按照长度排序
}
int pp(int p)
{
int flag;
int pi;
for (int i=; i<=word[p].len-word[p-].len; i++)
{
flag=;
pi=i;
for(int j=; j<word[p-].len;j++)
{
if(word[p].sub[pi]!=word[p-].sub[j])
{
flag=;
break;
}
else
{
pi++;
continue;
}
}
if (flag==)break;
}
if (flag==)return ;
else return ;
}
int main()
{
int n;
int lens;
int flag;
while (~scanf("%d",&n))
{
flag=;
for (int i=; i<n; i++)
{
scanf("%s",word[i].sub);
lens=strlen(word[i].sub);
word[i].len=lens;
}
sort(word,word+n,cmp);
for (int i=n-; i>; i--)
{
if(pp(i)!=){
flag=;
break;
}
}
if(flag==)printf("NO\n");
else
{
printf("YES\n");
for (int i=; i<n; i++)
{
printf("%s\n",word[i].sub);
}
}
}
return ;
}

Codeforces Round #486 (Div. 3)-B. Substrings Sort的更多相关文章

  1. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  2. Codeforces Round #486 (Div. 3) E. Divisibility by 25

    Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  3. Codeforces Round #486 (Div. 3) D. Points and Powers of Two

    Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvo ...

  4. Codeforces Round #486 (Div. 3) A. Diverse Team

    Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...

  5. Codeforces Round #648 (Div. 2) B. Trouble Sort

    一开始读错题了...想当然地认为只能相邻元素交换...(然后换了两种写法WA了4发,5分钟切A的优势荡然无存) 题目链接:https://codeforces.com/contest/1365/pro ...

  6. Codeforces Round #198 (Div. 2) D. Bubble Sort Graph (转化为最长非降子序列)

    D. Bubble Sort Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #212 (Div. 2) C. Insertion Sort

    C. Insertion Sort Petya is a beginner programmer. He has already mastered the basics of the C++ lang ...

  8. Codeforces Round #486 (Div. 3)988D. Points and Powers of Two

    传送门:http://codeforces.com/contest/988/problem/D 题意: 在一堆数字中,找出尽量多的数字,使得这些数字的差都是2的指数次. 思路: 可以知道最多有三个,差 ...

  9. Codeforces Round #650 (Div. 3) F1. Flying Sort (Easy Version) (离散化,贪心)

    题意:有一组数,每次操作可以将某个数移到头部或者尾部,问最少操作多少次使得这组数非递减. 题解:先离散化将每个数映射为排序后所对应的位置,然后贪心,求最长连续子序列的长度,那么最少的操作次数一定为\( ...

随机推荐

  1. [20180918]文件格式与sql_id.txt

    [20180918]文件格式与sql_id.txt --//记录测试中遇到的一个问题.这是我在探究SQL*Net more data from client遇到的问题.--//就是实际oracle会把 ...

  2. .net core系列之《.net core内置IOC容器ServiceCollection》

    一.IOC介绍 IOC:全名(Inversion of Control)-控制反转 IOC意味着我们将对象的创建控制权交给了外部容器,我们不管它是如何创建的,我们只需要知道,当我们想要某个实例时,我们 ...

  3. c/c++ 标准库 pair 介绍

    标准库 pair 介绍 问题:map里的元素由key和value组成,这个key和value的组合是什么类型呢??? 答案:pair类型 pair介绍: 它是模板 有2个公有成员可供访问. first ...

  4. Win10 - MySQL-zip安装方法

    Win10 - MySQL-zip安装方法 安装步骤 1.下载,到MySQL官网:https://dev.mysql.com/downloads/mysql/ 2.解压安装包 解压下载的安装包,放到你 ...

  5. GitLab安装及使用

    GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目. GitLab拥有与Github类似的功能,能够浏览 ...

  6. Java序列化(含transient)

    什么是序列化? 我们创建的对象只有在Java虚拟机保持运行时,才会存在于内存中.如果想要超出Java虚拟机的生命周期,就可以将对象序列化,将对象状态转换为字节序列,写入文件(或socket传输),后面 ...

  7. 在win10 64位系统安装 lxml (Python 3.5)

    本想直接用pip install lxml 命令安装完事,但是由于安装过程中跟VS的一些东西冲突怎么都安装不上,搜索到以下方法,问题解决. 步骤: 1.下载跟python匹配的.whl 文件(lxml ...

  8. 【Linux基础】VI 编辑器基本使用方法

    vi编辑器是所有Unix及Linux系统下标准的编辑器.对Unix及Linux系统的任何版本,vi编辑器是完全相同的,它是Linux中最基本的文本编辑器. 第一章vi的三种模式 第二章vi文本编辑器 ...

  9. POJ 3970(最小公倍数LCM)

    版权声明:Site:https://skyqinsc.github.io/ https://blog.csdn.net/u013986860/article/details/26182055  知 ...

  10. Fiddler抓包学习

    今天看到一个抓包笔记, 因为是老早抓包的需求, 后期不用就忘了, 换电脑桌面软件图标都没了, 点开看了一下一脸懵逼... 这是啥...  以后有需要在看一遍吧! Fiddler抓包使用教程-扫盲篇 h ...