#include <iostream>
#include <string>
#include <fstream>
#include <map>
#include <utility>
#include <sstream>
using namespace std;
int main(int argc,char **argv)
{
ifstream in1("in1");
ifstream in2("in2");
ofstream out("out");
string key,value;
string inString;
string outString;
map<string,string> trans_map;
if(!in1.good())
{
cerr << "open in1 error!\n";
return -1;
}
if(!in2.good())
{
cerr << "open in2 error\n";
return -1;
}
while(in1 >> key >> value)
{
trans_map.insert(make_pair(key,value));
}
map<string,string>::iterator map_it;
string line;
while(getline(in2,line))
{
istringstream stream(line);
while(stream >> inString)
{
map_it = trans_map.find(inString);
if(map_it != trans_map.end())
out << map_it->second<<" ";
}
out << endl;
}
in1.close();
in2.close();
out.close();
return 0;
}
|