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. 自动获取svn的版本号

    需求 在做打包时,需要获取本地svn仓库的版本号,如下所示: 下面是我试过的几种做法 SubWCRev 使用SubWCRev.exe(TortoiseSVN自带的小工具),用法简单,但获取到的版本号有 ...

  2. Vue学习之路8-v-on指令学习简单事件绑定之属性

    前言 上一篇文章以v-on指令绑定click事件为例介绍了v-on指令的使用方法,本文介绍一下v-on绑定事件的一些属性的使用方法. v-on绑定指令属性 .stop属性 阻止单击事件继续向上传播(简 ...

  3. 【算法】LeetCode算法题-Remove Element

    这是悦乐书的第150次更新,第152篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第9题(顺位题号是27).给定整数数组nums和值val,删除nums中所有的val值, ...

  4. JavaScript中的Generator函数

    1. 简介 Generator函数时ES6提供的一种异步编程解决方案.Generator语法行为和普通函数完全不同,我们可以把Generator理解为一个包含了多个内部状态的状态机. 执行Genera ...

  5. [福大软工] Z班 团队作业——随堂小测(同学录) 作业成绩

    团队作业--随堂小测(同学录) 作业链接 http://www.cnblogs.com/easteast/p/7763645.html 作业情况 本次作业从原先预计的3小时,有些组打了鸡血连续肝了4. ...

  6. 【工匠大道】升级Mac下的svn,解决命令行不能使用svn的问题

    本文地址 原文地址 一. 为什么要升级SVN? 因为MAC上默认安装的是1.6版本,在使用时经常会提示SVN版本太旧,所以一定要升级 二. 怎么升级? 所有软件安装都是这三步吧,哈哈 第一步: 下载 ...

  7. Apache Spark技术实战之6 --Standalone部署模式下的临时文件清理

    问题导读 1.在Standalone部署模式下,Spark运行过程中会创建哪些临时性目录及文件? 2.在Standalone部署模式下分为几种模式? 3.在client模式和cluster模式下有什么 ...

  8. 【ZJOI2012】灾难

    [ZJOI2012]灾难 阿米巴是小强的好朋友. 阿米巴和小强在草原上捉蚂蚱.小强突然想,如果蚂蚱被他们捉灭绝了,那么吃蚂蚱的小鸟就会饿死,而捕食小鸟的猛禽也会跟着灭绝,从而引发一系列的生态灾难. 学 ...

  9. googLeNet网络

    1.什么是inception结构 2.什么是Hebbian原理 3.什么是多尺度处理 最近深度学习的发展,大多来源于新的想法,算法以及网络结构的改善,而不是依赖于硬件,新的数据集,更深的网络,并且深度 ...

  10. 如何在excel单元格中插入图片批注

    在excel单元格中插入图片批注的方法: 1.选定要插入图片的单元格,然后右键选择插入批注. 2.然后会插入一个批注框,为了不影响图片效果,可以将批注文字都删除.然后鼠标移动到批注框边角再右键. 3. ...