codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

53A.md (1736B)


      1 Source: https://codeforces.com/problemset/problem/53/A
      2 
      3 A. Autocomplete
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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*.
     22 
     23 Input
     24 
     25 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.
     26 
     27 Output
     28 
     29 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*.
     30 
     31 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.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 next  
     39 2  
     40 nextpermutation  
     41 nextelement
     42 ```
     43 
     44 Output
     45 
     46 ```
     47 nextelement
     48 ```
     49 
     50 Input
     51 
     52 ```
     53 find  
     54 4  
     55 find  
     56 findfirstof  
     57 findit  
     58 fand
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 find
     65 ```
     66 
     67 Input
     68 
     69 ```
     70 find  
     71 4  
     72 fondfind  
     73 fondfirstof  
     74 fondit  
     75 fand
     76 ```
     77 
     78 Output
     79 
     80 ```
     81 find
     82 ```