Advertisement
amermo

TP T-4 Z5

Mar 24th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. template <typename TipVektora>
  6. std::vector<TipVektora> Presjek(const std::vector<TipVektora> &v1, const std::vector<TipVektora> &v2)
  7. {
  8.     std::vector<TipVektora> v3;
  9.     for(unsigned int i(0); i < v1.size(); i++)
  10.     {
  11.         bool sadrzi(false);
  12.         for(unsigned int j(0); j < v2.size(); j++)
  13.             if(v1.at(i) == v2.at(j))
  14.                 sadrzi = true;
  15.         if(sadrzi)
  16.             v3.push_back(v1.at(i));
  17.     }
  18.     for(unsigned int i(0); i < v3.size(); i++)
  19.     {
  20.         for(unsigned int j(i+1); j < v3.size(); j++)
  21.         {
  22.             if(v3.at(i) == v3.at(j))
  23.             {
  24.                 v3.erase(v3.begin()+j);
  25.                 j--;
  26.             }
  27.         }
  28.     }
  29.     return v3;
  30. }
  31.  
  32. int main()
  33. {
  34.     std::vector<int> v1 {3, 6, 6, 6, 6, 4, 2, 5}, v2 {4, 6, 3, 6, 4, 2, 5};
  35.     std::vector<int> v3(Presjek(v1, v2));
  36.     for(auto x : v3)
  37.         std::cout << x << " ";
  38.     std::cout << std::endl;
  39.     std::vector<std::string> v4{"testiramo", "ova", "ova", "dupla", "nije", "testiramo"}, v5{"ova", "ova", "testiramo", "rubni"};
  40.     std::vector<std::string> v6(Presjek(v4, v5));
  41.     for(auto x : v6)
  42.         std::cout << x << " ";
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement