2个回答
展开全部
#include <map>
class Word
{
public:
World();
// ...
protected:
std::string m_english;
std::string m_chinese;
//std::string m_;....
// => std::vector<std::string> m_info;
};
class Dictionary
{
public:
Dictionary();
//....
void Query(std::string word);
protected:
std::map<std::string, class Word> m_wordTable;
//...
};
class Word
{
public:
World();
// ...
protected:
std::string m_english;
std::string m_chinese;
//std::string m_;....
// => std::vector<std::string> m_info;
};
class Dictionary
{
public:
Dictionary();
//....
void Query(std::string word);
protected:
std::map<std::string, class Word> m_wordTable;
//...
};
展开全部
#include "stdafx.h"
#include <map>
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
/*class define*/
class dic
{
private:
map<string, string> t;
public:
dic();
void add(string sword, string smean);
string trans(string sentence);
};
dic::dic()
{}
void dic::add(string sword, string smean)
{
t.insert(pair<string,string>(sword, smean));
}
string dic::trans(string sentence)
{
string s, sres = "";
istringstream iss(sentence);
map<string,string>::iterator iter=t.begin();
int c = 0;
while (iss>>s)
{
iter = t.find(s);
if (iter == t.end())
continue;
sres += iter->second;
}
return sres;
}
/*class define ended!!*/
/*main interface */
int main(int argc, char* argv[])
{
dic a;
a.add("hello", "你好");
a.add("china", "中国");
cout<<a.trans("hello china d");
return 0;
}
#include <map>
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
/*class define*/
class dic
{
private:
map<string, string> t;
public:
dic();
void add(string sword, string smean);
string trans(string sentence);
};
dic::dic()
{}
void dic::add(string sword, string smean)
{
t.insert(pair<string,string>(sword, smean));
}
string dic::trans(string sentence)
{
string s, sres = "";
istringstream iss(sentence);
map<string,string>::iterator iter=t.begin();
int c = 0;
while (iss>>s)
{
iter = t.find(s);
if (iter == t.end())
continue;
sres += iter->second;
}
return sres;
}
/*class define ended!!*/
/*main interface */
int main(int argc, char* argv[])
{
dic a;
a.add("hello", "你好");
a.add("china", "中国");
cout<<a.trans("hello china d");
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询