0
点赞
收藏
分享

微信扫一扫

B. Lecture字符串的处理问题 包含strcmp 与字符串数组

鲤鱼打个滚 2022-06-29 阅读 150

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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
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.

The following 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 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.

The next line contains 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}.

All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.

Output
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.

Examples
inputCopy
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
outputCopy
codeforces round letter round
inputCopy
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
outputCopy
hbnyiyc joll joll un joll
这个题是真的碰到盲点了,开始用string不可以,stl又不会。
不明白结构体里面为什么必须是char型(确实是一个好方法)的才能比较长度,记住了。
还有一个地方,边输入,边比较,按回车之后才会全部释放。

///***Created by Xiang wang *** ACMÈÙҫ֮·***
//#include <bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<cmath>
#include<cctype>
#include<stack>
#include<map>
#include<string>
#include<cstdlib>
#define ll long long
const int INF = 0x3f3f3f3f;
const long long LIMIT = 4294967295LL;
const int maxn = 100 + 10;
using namespace std;
struct node{
char a[100];
char b[100];}q[3001];
char c[1110];
int main(){
int n,m,i;
cin>>n>>m;
for(i=1;i<=m;i++)
cin>>q[i].a>>q[i].b;
while(n--)
{
cin>>c;
for(i=1;i<=m;i++)
if(strcmp(c,q[i].a)==0||strcmp(c,q[i].b)==0){
{if(strlen(q[i].a)>strlen(q[i].b))
cout<<q[i].b<<' ';
else cout<<q[i].a<<' ';
}
break;
}
}
return 0;
}


举报

相关推荐

0 条评论