#include?<iostream>
#include?<stdio.h>
using?namespace?std;
#define?MAXN?100
class?Dictionary{
public:
Dictionary()?{cnt=0;};//初始詞條數為0
void?put(string?a,string?b)
{
e[cnt]=a;
c[cnt++]=b;?//存入壹條詞條
}
string?get(string?a)
{
for(int?i=0;i<cnt;i++)
if(e[i]==a)?{
return?c[i];
}
}
private:
int?cnt;//詞條數
string?e[MAXN];//英語單詞
string?c[MAXN];//中文解釋(下表與e數組對應)
};
int?main()
{
//freopen("in.txt","r",stdin);
Dictionary?dictionary;
//?initialize?dictionary
while?(true)?{
string?english;
cin?>>?english;
if?(english?==?"end")?break;
string?chinese;
cin?>>?chinese;
dictionary.put(english,?chinese);
}
//?lookup?dictionary
while?(true)?{
string?english;
cin?>>?english;
if?(english?==?"end")?break;
cout?<<?dictionary.get(english)?<<?endl;
}
return?0;
}
找不到的情況,我不知道妳的題目是怎麽規定的,所以沒有寫
另外不知道妳能存多少詞條,所以先定了MAXN=100條詞條,也就最多能存100
另外在查找的時候用的是暴搜,因為不知道妳對搜索性能是否有要求
測試過了,樣例能通過