//8、设计一个词典类Dictionary,每个单词包括英文单词及对应的中文含义。
// 并有一个英汉翻译成员函数,通过查字典的方式将一段英语翻译成对应的汉语。
#include <iostream>
#include <string>
#include <map>
using namespace std ;
typedef map<string, string> STRING2INT;
int main()
...{
cout << "输入您想翻译的文章:";
STRING2INT MyMap;
STRING2INT::iterator MyIterator;
string MyBuffer;
MyMap["I"] = "我";
MyMap["am"] = "是";
MyMap["chinese"] = "中国人";
MyMap["live"] = "住在";
MyMap["jiangsu"] = "江苏";
MyMap["nanjing"] = "南京";
MyMap["xianlin"] = "仙林";
MyMap["shifan"] = "师范";
MyMap["daxue"] = "大学";
MyMap["zijin"] = "紫金";
MyMap["suiyuan"] = "随原";
MyMap["xiaoqu"] = "校区";
MyIterator = MyMap.end();
while (MyIterator == MyMap.end())
...{
while(cin >> MyBuffer )
...{
if ((MyIterator = MyMap.find(MyBuffer)) != MyMap.end())
cout << (*MyIterator).second ;
else
cout << "Enter a Valid Month (example: March)" << endl;
}
}
MyMap.clear();
}
// 并有一个英汉翻译成员函数,通过查字典的方式将一段英语翻译成对应的汉语。
#include <iostream>
#include <string>
#include <map>
using namespace std ;
typedef map<string, string> STRING2INT;
int main()
...{
cout << "输入您想翻译的文章:";
STRING2INT MyMap;
STRING2INT::iterator MyIterator;
string MyBuffer;
MyMap["I"] = "我";
MyMap["am"] = "是";
MyMap["chinese"] = "中国人";
MyMap["live"] = "住在";
MyMap["jiangsu"] = "江苏";
MyMap["nanjing"] = "南京";
MyMap["xianlin"] = "仙林";
MyMap["shifan"] = "师范";
MyMap["daxue"] = "大学";
MyMap["zijin"] = "紫金";
MyMap["suiyuan"] = "随原";
MyMap["xiaoqu"] = "校区";
MyIterator = MyMap.end();
while (MyIterator == MyMap.end())
...{
while(cin >> MyBuffer )
...{
if ((MyIterator = MyMap.find(MyBuffer)) != MyMap.end())
cout << (*MyIterator).second ;
else
cout << "Enter a Valid Month (example: March)" << endl;
}
}
MyMap.clear();
}