CF53A.Autocomplete

普及/提高-

通过率:0%

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 nn last visited by the user pages and the inputted part ss are known. Your task is to complete ss to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix ss .

输入格式

The first line contains the ss line which is the inputted part. The second line contains an integer nn ( 1<=n<=1001<=n<=100 ) which is the number of visited pages. Then follow nn lines which are the visited pages, one on each line. All the lines have lengths of from 11 to 100100 symbols inclusively and consist of lowercase Latin letters only.

输出格式

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

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.

输入输出样例

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