Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. /* TP, 2017/2018, Tutorijal 3, Zadatak 1 */
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. bool ParNeparSum (int vektora)
  6. {
  7.     int suma(0),cifra(0);
  8.    /* if (vektora<0) {
  9.         vektora*=(-1);
  10.     } */
  11.     while (vektora!=0) {
  12.         cifra=vektora%10;
  13.         suma+=cifra;
  14.         vektora/=10;
  15.     }
  16.     if (suma%2!=0) return false;
  17.  
  18.     return true;
  19. }
  20.  
  21.  
  22. std::vector<int> IzdvojiElemente (std::vector<int> V1 , bool Value)
  23. {
  24.     std::vector<int> Novi;
  25.     if (Value) {
  26.         for (int x: V1) {
  27.             if (ParNeparSum(x)) {
  28.                 Novi.push_back(x);
  29.             }
  30.         }
  31.         return Novi;
  32.     }
  33.    
  34.     for (int x: V1) {
  35.             if (ParNeparSum(x)==0) {
  36.                 Novi.push_back(x);
  37.             }
  38.         }
  39.         return Novi;
  40.  
  41. }
  42. int main ()
  43. {
  44.     int vel, el;
  45.     std::cout<<"Koliko zelite unijeti elemenata: ";
  46.     std::cin>>vel;
  47.     if (vel==0) {
  48.         std::cout<<"Broj elemenata mora biti veci od 0!";
  49.         return 0;
  50.     }
  51.    
  52.     std::cout<<"Unesite elemente: ";
  53.     std::vector<int> UN;
  54.     for (int i(0); i<vel; i++) {
  55.         std::cin>>el;
  56.         UN.push_back(el);
  57.     }
  58.     std::vector<int> Par;
  59.     std::vector<int> Nepar;
  60.     Par= IzdvojiElemente (UN,1);
  61.     Nepar= IzdvojiElemente (UN,0);
  62.     for (int x: Par) std::cout<<x<<" ";
  63.     std::cout<<std::endl;
  64.     for (int x: Nepar) std::cout<<x<<" ";
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement