真是有点懒了,做完这么久才想起记下来。
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.
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 cibelongs 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 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.
意思很好懂,不过这次想联系个类。string类的长度都是成员函数可以用的,用strlen弄了半天,string.size() 记下了。
#include<iostream>
#include<cstring>
#define MAXN 3000+5
using namespace std;
class dict
{
public:
string a[MAXN];
string b[MAXN];
string sht(string &str1,string &str2)
{
if(str1.size()>str2.size())return str2;
else return str1;
}
};
string s[MAXN];
string len[MAXN];
int main()
{
dict way;
int m,n;
cin>>m>>n;
for(int i=0;i<n;i++)
{
cin>>way.a[i]>>way.b[i];
}
for(int i=0;i<m;i++)
{
cin>>s[i];
for(int j=0;j<n;j++)
{
if(s[i]==way.a[j]||s[i]==way.b[j])len[i]=way.sht(way.a[j],way.b[j]);
}
}
for(int i=0;i<m;i++)
cout<<len[i]<<" ";
cout<<endl;
return 0;
}
本文探讨了一种高效记录使用不同语言教授讲座内容的方法。通过对比两种语言的独特词汇,作者提出了一套策略来简化笔记过程。利用字符串长度比较和对应词汇的唯一性,实现了快速准确地将讲座内容转化为个人笔记。该方法不仅节省了时间,还确保了笔记的准确性。文章详细介绍了输入数据结构、核心算法以及最终输出结果的生成过程。
598

被折叠的 条评论
为什么被折叠?



