B. Lecture
time limit per test
memory limit per test
input
output
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.
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.
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.
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.
Input
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.
m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi
n space-separated strings c1, c2, ..., cn — the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}.
10
Output
n
Examples
input
4 3 codeforces codesecrof contest round letter message codeforces contest letter contest
output
codeforces round letter round
input
5 3 joll wuqrd euzf un hbnyiyc rsoqqveh hbnyiyc joll joll euzf joll
output
hbnyiyc joll joll un joll
题意:m对,左右两边是映射关系,求n个单词的笔记(左右意思相同,让求最短的单词)。
#include<stdio.h>
#include<string.h>
#include<map>
#include<string>
#include<iostream>
using namespace std;
int main()
{
int n,m;
map<string,string>ff;
scanf("%d%d",&n,&m);
string a,b;
for(int i=0; i<m; i++)
{
cin>>a>>b;
ff[a]=b;
}
string x;
for(int i=0; i<n; i++)
{
cin>>x;
if(i==0)
{
if(x.size()<=ff[x].size())
cout<<x;
else
cout<<ff[x];
}
else
{
if(x.size()<=ff[x].size())
cout<<' '<<x;
else
cout<<' '<<ff[x];
}
}
printf("\n");
return 0;
}