5244: 自动补全

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:11 通过:9

题目描述

Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of $ n $ last visited by the user pages and the inputted part $ s $ are known. Your task is to complete $ s $ to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix $ s $ .

自动补全是一个程序功能,允许在输入文本(在编辑器,命令行l,浏览器等)的时候通过其输入部分完成剩下的文本。Vasya正忙着开发一款名为“BERowser”的新浏览器。此时此刻,他碰巧正在处理地址行的自动补全功能。已知$ n $个用户已经访问过的页面和已经输入的部分$ s $。您的任务是补全$ s $,使其成为列表中某一页的地址。您必须找到具有前缀$ s $的按字典顺序最小的地址。

输入格式

The first line contains the $ s $ line which is the inputted part. The second line contains an integer $ n $ ( $ 1 \leq n \leq 100 $ ) which is the number of visited pages. Then follow $ n $ lines which are the visited pages, one on each line. All the lines have lengths of from $ 1 $ to $ 100 $ symbols inclusively and consist of lowercase Latin letters only.

第一行为$s$,即已经输入的文本。第二行有一个整数$n$($1 \leq n \leq 100 $),代表已经访问过的页面的个数。接下来$n$行即访问的页面,每行一行。所有行的长度为$1$到$100$个符号(包括在内),仅由小写拉丁字母组成。

输出格式

If $ s $ is not the beginning of any of $ n $ addresses of the visited pages, print $ s $ . Otherwise, print the lexicographically minimal address of one of the visited pages starting from $ s $ .

The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.

如果$s$不是被访问页面的n个地址中的任何一个的开始,则打印$s$。否则,打印从$s$开始的被访问页面之一的字典最小地址。

字典序是指字典中单词的顺序。在现代编程语言中,行之间的字典比较是通过'<'操作符实现的。

输入样例 复制

next
2
nextpermutation
nextelement

输出样例 复制

nextelement

数据范围与提示

样例输入 #1

next
2
nextpermutation
nextelement

样例输出 #1

nextelement

样例输入 #2

find
4
find
findfirstof
findit
fand

样例输出 #2

find

样例输入 #3

find
4
fondfind
fondfirstof
fondit
fand

样例输出 #3

find