Advertisement
amermo

TP T-8 Z4

Apr 27th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <cctype>
  5.  
  6. std::string ZamijeniPremaRjecniku(const std::string &s, std::map<std::string, std::string> mapa)
  7. {
  8.     std::string rezultat;
  9.     for (unsigned int i(0); i < s.length(); i++)
  10.     {
  11.         if (isalpha(s[i]))
  12.         {
  13.             std::string temp;
  14.             for (; s[i] != ' ' && i < s.length(); i++)
  15.                 temp.push_back(s[i]);
  16.             auto nasao(mapa.find(temp));
  17.             if (nasao != mapa.end())
  18.                 for (auto p(nasao->second.begin()); p != nasao->second.end(); p++)
  19.                     rezultat.push_back(*p);
  20.             else
  21.                 for (auto p(temp.begin()); p != temp.end(); p++)
  22.                     rezultat.push_back(*p);
  23.         }
  24.             rezultat.push_back(s[i]);
  25.     }
  26.     return rezultat;
  27. }
  28.  
  29. int main()
  30. {
  31.     std::map<std::string, std::string> moj_rjecnik{ { "jabuka", "apple" }, { "da", "yes" }, { "kako", "how" }, { "ne", "no" }, { "majmun", "monkey" }};
  32.     std::cout << ZamijeniPremaRjecniku("kako majmun guli jabuka", moj_rjecnik) << std::endl;
  33.     system("PAUSE");
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement