Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- #include <cctype>
- std::string ZamijeniPremaRjecniku(const std::string &s, std::map<std::string, std::string> mapa)
- {
- std::string rezultat;
- for (unsigned int i(0); i < s.length(); i++)
- {
- if (isalpha(s[i]))
- {
- std::string temp;
- for (; s[i] != ' ' && i < s.length(); i++)
- temp.push_back(s[i]);
- auto nasao(mapa.find(temp));
- if (nasao != mapa.end())
- for (auto p(nasao->second.begin()); p != nasao->second.end(); p++)
- rezultat.push_back(*p);
- else
- for (auto p(temp.begin()); p != temp.end(); p++)
- rezultat.push_back(*p);
- }
- rezultat.push_back(s[i]);
- }
- return rezultat;
- }
- int main()
- {
- std::map<std::string, std::string> moj_rjecnik{ { "jabuka", "apple" }, { "da", "yes" }, { "kako", "how" }, { "ne", "no" }, { "majmun", "monkey" }};
- std::cout << ZamijeniPremaRjecniku("kako majmun guli jabuka", moj_rjecnik) << std::endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement