#include<iostream>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<fstream>
#include<sstream>
using namespace std;
map<string,string> tomap(const string &rule)
{
map<string, string> keys;
ifstream in(rule);
string line;
bool first = true;
string value, key;
while (getline(in, line))
{
istringstream is(line);
string word;
while (is >> word)
{
if (first)
{
key = word;
first = false;
}
else
{
value = word;
keys[key] = value;
first = true;
}
}
}
in.close();
return keys;
}
void translate(const string &rule, const string &trans,const string &tofile)
{
map<string,string> keys = tomap(rule);
ifstream in(trans);
string line;
ofstream os(tofile);
while (getline(in, line))
{
istringstream is(line);
string word;
while (is >> word)
{
auto every = keys.find(word);
if (every != keys.end())
os << every->second;
else
os << word;
os << " ";
}
}
os.close();
in.close();
}
int main()
{
translate("rule.txt", "translate.txt", "wh.txt");
system("pause");
return 0;
}
#include<set>
#include<map>
#include<utility>
#include<string>
#include<fstream>
#include<sstream>
using namespace std;
map<string,string> tomap(const string &rule)
{
map<string, string> keys;
ifstream in(rule);
string line;
bool first = true;
string value, key;
while (getline(in, line))
{
istringstream is(line);
string word;
while (is >> word)
{
if (first)
{
key = word;
first = false;
}
else
{
value = word;
keys[key] = value;
first = true;
}
}
}
in.close();
return keys;
}
void translate(const string &rule, const string &trans,const string &tofile)
{
map<string,string> keys = tomap(rule);
ifstream in(trans);
string line;
ofstream os(tofile);
while (getline(in, line))
{
istringstream is(line);
string word;
while (is >> word)
{
auto every = keys.find(word);
if (every != keys.end())
os << every->second;
else
os << word;
os << " ";
}
}
os.close();
in.close();
}
int main()
{
translate("rule.txt", "translate.txt", "wh.txt");
system("pause");
return 0;
}