n, m = map(int, input().split())
h = {}
for _ in range(m):
k, v = input().split()
h[k] = v if len(v) < len(k) else k
a = input().split()
for i in range(n):
a[i] = h[a[i]]
print(' '.join(a))
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
using namespace std;
#define ll long long
int main()
{
int n, m;
cin >> n >> m;
string s1, s2;
map<string, string>mm;
for (int i = 0; i < m; i++) {
cin >> s1 >> s2;
if (s1.length() <= s2.length()) {
mm[s1] = s1;
}
else {
mm[s1] = s2;
}
}
string s;
for (int i = 0; i < n; i++) {
cin >> s;
cout << mm[s] << " ";
}
}
33. Search in Rotated Sorted Array | 17. Letter Combinations of a Phone Number |
5. Longest Palindromic Substring | 3. Longest Substring Without Repeating Characters |
1312. Minimum Insertion Steps to Make a String Palindrome | 1092. Shortest Common Supersequence |
1044. Longest Duplicate Substring | 1032. Stream of Characters |
987. Vertical Order Traversal of a Binary Tree | 952. Largest Component Size by Common Factor |
212. Word Search II | 174. Dungeon Game |
127. Word Ladder | 123. Best Time to Buy and Sell Stock III |
85. Maximal Rectangle | 84. Largest Rectangle in Histogram |
60. Permutation Sequence | 42. Trapping Rain Water |
32. Longest Valid Parentheses | Cutting a material |
Bubble Sort | Number of triangles |
AND path in a binary tree | Factorial equations |
Removal of vertices | Happy segments |
Cyclic shifts | Zoos |
Build a graph | Almost correct bracket sequence |