1 #include 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 void transform(ifstream &mf, ifstream &wf); 9 10 int main() 11 { 12 ifstream f1("d:\\m.txt"); 13 ifstream f2("d:\\t.txt"); 14 transform(f1,f2); 15 return 0; 16 } 17 18 unordered_map buildMap(ifstream& fs) 19 { 20 unordered_map map; 21 string line, key; 22 while (fs >> key) { 23 getline(fs, line); 24 map[key] = line.substr(1); 25 } 26 return map; 27 } 28 29 string transword(string word, unordered_map & map) 30 { 31 auto it = map.find(word); 32 return it == map.end() ? word : map[word]; 33 } 34 35 void transform(ifstream &mf, ifstream &wf) 36 { 37 unordered_map map = buildMap(mf); 38 string word, line; 39 while (getline(wf, line)) { 40 bool head = true; 41 istringstream ss(line); 42 while (ss >> word) { 43 if (head) 44 head = false; 45 else 46 cout << " "; 47 cout << transword(word,map); 48 } 49 cout << endl; 50 } 51 return; 52 } 53 54 #include 55 #include
> m; 88 auto i = m.find(k); 89 map
>::iterator i = m.find(k); 90 91 key min 92 lower_bound m.begin() 93 upper_bound m.begin() 94 equal_range pair