Advertisement
aed1oN

Untitled

May 5th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4.  
  5. std::string ZamijeniPremaRjecniku(std::string recenica, std::map<std::string, std::string> rjecnik) {
  6.     std::string novaRecenica;
  7.     bool razmak = true;
  8.     for (int i = 0; i < recenica.length(); i++) {
  9.         if (recenica[i] == ' ') {
  10.             razmak = true;
  11.             novaRecenica += ' ';
  12.         }
  13.         else if (razmak) {
  14.             razmak = false;
  15.             std::string tmp;
  16.             int j = i;
  17.             while (j < recenica.length() && recenica[j] != ' ') {
  18.                 tmp.push_back(recenica[j]);
  19.                 j++;
  20.             }
  21.             auto it = rjecnik.find(tmp);
  22.             if (it != rjecnik.end()) {
  23.                 tmp = it->second;
  24.             }
  25.             novaRecenica += tmp;
  26.         }
  27.     }
  28.     return novaRecenica;
  29. }
  30. int main() {
  31.     std::map<std::string, std::string> moj_rjecnik{{"mart", "ozuljak"}, {"maj", "svibanj"}, {"juli", "srpanj"}};
  32.     std::cout << ZamijeniPremaRjecniku("davor martic ima sestre maju i juliju", moj_rjecnik);
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement