Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <istream>
  3. #include <fstream>
  4. #include <string>
  5. #include <algorithm>
  6. #include <map>
  7. #include <cstring>
  8.  
  9. using namespace std;
  10.  
  11. class change {
  12. public:
  13. change() {}
  14. void operator() (pair<string, string> list) {
  15. cout « list.first « " -> " « list.second « endl;
  16. }
  17. };
  18.  
  19. int main() {
  20. ifstream inFile1("zamena.txt");
  21. ifstream inFile2("text.txt");
  22. ofstream outFile("OutFile.txt");
  23. if (!inFile1 || !inFile2 || !outFile) {
  24. cerr « "ERROR: can't open stream" « endl
  25. « "Can't find files" « endl;
  26. }
  27.  
  28. map<string, string> mapp;
  29. map<string, string>::iterator itmapp;
  30.  
  31. string key;
  32. string value;
  33. while (!inFile1.eof()) {
  34. inFile1 » key;
  35. inFile1 » value;
  36. mapp[key] = value;
  37. }
  38.  
  39. for_each(mapp.begin(), mapp.end(), change());
  40.  
  41. string buf;
  42. int len;
  43. char p;
  44. while (!inFile2.eof()) {
  45. if (getline == "\n")
  46. outFile « '\n';
  47. inFile2 » buf;
  48. //cout « buf « endl;
  49. len = strlen(buf);
  50. if ((buf[len] == '.') || (buf[len] == '!') ||
  51. (buf[len] == '?') || (buf[len] == ',')) {
  52. p = buf[len];
  53. //cout « p « endl;
  54. buf[len] = "\0";
  55. //cout « buf « endl;
  56. if ((itmapp = mapp.find(buf)) != mapp.end()) {
  57. outFile « itmapp->second « p « " ";
  58. } else
  59. outFile « buf « p « " ";
  60. } else {
  61. if ((itmapp = mapp.find(buf)) != mapp.end()) {
  62. outFile « itmapp->second « " ";
  63. } else
  64. outFile « buf « " ";
  65. }
  66. }
  67.  
  68. inFile1.close();
  69. inFile2.close();
  70. outFile.close();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement