CF53A.Autocomplete

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

自动补全(Autocomplete)是一种程序功能,用于在编辑器、命令行终端、浏览器等环境中输入文本时,根据已输入的部分自动完成整个文本。瓦夏正在开发一款名为“BERowser”的新浏览器,此时他正专注于实现地址栏中的自动补全功能。已知一个包含用户最近访问过的 nn 个网页地址的列表,以及当前已输入的字符串 ss。你的任务是将 ss 补全为该列表中某个网页的完整地址,且要求所补全得到的地址是所有以 ss 为前缀的地址中字典序最小的一个。

输入格式

The first line contains the s line which is the inputted part. The second line contains an integer n (1 ≤ n ≤ 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.

第一行包含字符串 ss,表示输入的部分。第二行包含一个整数 nn(1 ≤ n ≤ 1001 ≤ n ≤ 100),表示访问的网页数量。接下来是 nn 行,每行一个访问过的网页。所有行的长度均为 11 至 100100 个字符(含端点),且仅由小写拉丁字母组成。

输出格式

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.

如果字符串 ss 不是任意一个已访问页面的 nn 个地址的开头,则输出 ss;否则,输出所有以 ss 开头的已访问页面地址中字典序最小的一个。

字典序即单词在字典中的排列顺序。字符串的字典序比较在现代编程语言中通过 < 运算符实现。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页