Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TP, 2017/2018, Tutorijal 3, Zadatak 1 */
- #include <iostream>
- #include <vector>
- bool ParNeparSum (int vektora)
- {
- int suma(0),cifra(0);
- /* if (vektora<0) {
- vektora*=(-1);
- } */
- while (vektora!=0) {
- cifra=vektora%10;
- suma+=cifra;
- vektora/=10;
- }
- if (suma%2!=0) return false;
- return true;
- }
- std::vector<int> IzdvojiElemente (std::vector<int> V1 , bool Value)
- {
- std::vector<int> Novi;
- if (Value) {
- for (int x: V1) {
- if (ParNeparSum(x)) {
- Novi.push_back(x);
- }
- }
- return Novi;
- }
- for (int x: V1) {
- if (ParNeparSum(x)==0) {
- Novi.push_back(x);
- }
- }
- return Novi;
- }
- int main ()
- {
- int vel, el;
- std::cout<<"Koliko zelite unijeti elemenata: ";
- std::cin>>vel;
- if (vel==0) {
- std::cout<<"Broj elemenata mora biti veci od 0!";
- return 0;
- }
- std::cout<<"Unesite elemente: ";
- std::vector<int> UN;
- for (int i(0); i<vel; i++) {
- std::cin>>el;
- UN.push_back(el);
- }
- std::vector<int> Par;
- std::vector<int> Nepar;
- Par= IzdvojiElemente (UN,1);
- Nepar= IzdvojiElemente (UN,0);
- for (int x: Par) std::cout<<x<<" ";
- std::cout<<std::endl;
- for (int x: Nepar) std::cout<<x<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement