codeforces-scrape

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

499B.md (2566B)


      1 Source: https://codeforces.com/problemset/problem/499/B
      2 
      3 B. Lecture
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
     22 
     23 You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
     24 
     25 You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
     26 
     27 You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
     28 
     29 Input
     30 
     31 The first line contains two integers, *n* and *m* (1 ≤ *n* ≤ 3000, 1 ≤ *m* ≤ 3000) — the number of words in the professor's lecture and the number of words in each of these languages.
     32 
     33 The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
     34 
     35 The next line contains *n* space-separated strings *c*1, *c*2, ..., *c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1, *a*2, ... *a**m*}.
     36 
     37 All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
     38 
     39 Output
     40 
     41 Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 4 3  
     49 codeforces codesecrof  
     50 contest round  
     51 letter message  
     52 codeforces contest letter contest
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 codeforces round letter round
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 5 3  
     65 joll wuqrd  
     66 euzf un  
     67 hbnyiyc rsoqqveh  
     68 hbnyiyc joll joll euzf joll
     69 ```
     70 
     71 Output
     72 
     73 ```
     74 hbnyiyc joll joll un joll
     75 ```