daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // DaLiJeSimetricna.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <iterator>
  6.  
  7. std::vector<std::string> IzdvojiPodstringove(std::string recenica) {
  8.     auto it(recenica.begin());
  9.     while (!(*it >= 'A' && *it <= 'Z' || *it >= 'a' && *it <= 'z')) ++it;
  10.     std::vector<std::string> Kontejner;
  11.     auto pocetak(it);
  12.     while (it != recenica.end()) {
  13.         if (!(*it >= 'A' && *it <= 'Z' || *it >= 'a' && *it <= 'z') && it != recenica.end()-1 || (it+1) == recenica.end()) {
  14.             std::string temp;
  15.             while (pocetak != it && (*pocetak >= 'A' && *pocetak <= 'Z' || *pocetak >= 'a' && *pocetak <= 'z')) {
  16.                 temp.push_back(*pocetak);
  17.                 ++pocetak;
  18.             }
  19.             if ((it + 1) == recenica.end()) temp.push_back(recenica.at(recenica.length() - 1));
  20.             if(!temp.empty())Kontejner.push_back(temp);
  21.             temp.clear(); it = pocetak;
  22.             ++pocetak;
  23.         }
  24.         ++it;
  25.     }
  26.     return Kontejner;
  27. }
  28.  
  29. std::vector<std::string> NadjiSimetricneRijeci(std::string recenica) {
  30.     auto Podstringovi(IzdvojiPodstringove(recenica));
  31.     bool ubaci(true);
  32.     std::vector<std::string> SimetricneRijeci;
  33.     for (int i(0); i < Podstringovi.size(); ++i) {
  34.         for (int j(0); j < Podstringovi.at(i).size()/2; ++j) {
  35.             ubaci = true;
  36.             if (Podstringovi.at(i).at(j) != Podstringovi[i][Podstringovi[i].size() -1 - j]) {
  37.                 ubaci = false; break;
  38.             }
  39.         }
  40.         if (ubaci) {
  41.             SimetricneRijeci.push_back(Podstringovi.at(i));
  42.         }
  43.     }
  44.     return SimetricneRijeci;
  45. }
  46.  
  47. int main()
  48. {
  49.     std::cout << "Unesite recenicu: ";
  50.     std::string recenica;
  51.     std::getline(std::cin, recenica);
  52.     std::cout << "Simetricne rijeci unutar recenice su: ";
  53.     std::vector<std::string> VektorRijeci(NadjiSimetricneRijeci(recenica));
  54.     if (VektorRijeci.empty()) std::cout << "Recenica ne sadrzi simetricne rijeci!";
  55.     else {
  56.         for (int i(0); i < VektorRijeci.size(); ++i) std::cout << VektorRijeci.at(i) << std::endl;
  57.     }
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top