Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- std::string ZamijeniPremaRjecniku(std::string recenica, std::map<std::string, std::string> rjecnik) {
- std::string novaRecenica;
- bool razmak = true;
- for (int i = 0; i < recenica.length(); i++) {
- if (recenica[i] == ' ') {
- razmak = true;
- novaRecenica += ' ';
- }
- else if (razmak) {
- razmak = false;
- std::string tmp;
- int j = i;
- while (j < recenica.length() && recenica[j] != ' ') {
- tmp.push_back(recenica[j]);
- j++;
- }
- auto it = rjecnik.find(tmp);
- if (it != rjecnik.end()) {
- tmp = it->second;
- }
- novaRecenica += tmp;
- }
- }
- return novaRecenica;
- }
- int main() {
- std::map<std::string, std::string> moj_rjecnik{{"mart", "ozuljak"}, {"maj", "svibanj"}, {"juli", "srpanj"}};
- std::cout << ZamijeniPremaRjecniku("davor martic ima sestre maju i juliju", moj_rjecnik);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement