Advertisement
sellmmaahh

TP-tut5-zad3-b

Sep 3rd, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main ()
  8. {
  9.     vector<int> v= {12,2,6,55,2,9,7,2,14,8};
  10.     cout<<"Najveci element: "<<*(max_element(v.begin(),v.end()))<<endl;
  11.  
  12.     cout<<"Najmanji element se ponavlja "<<count(v.begin(),v.end(),*(min_element(v.begin(),v.end())))<<" puta."<<endl;
  13.     cout<<"Brojeva koji su stepeni dvojke ima: "<<count_if(v.begin(),v.end(),[](int n)
  14.     {
  15.         for (int i=0; i<20; i++)
  16.         {
  17.             if (pow(2,i)==n) return true;
  18.         }
  19.         return false;
  20.     })<<"."<<endl;
  21.  
  22.     cout<<"Element sa najmanjom sumom cifara je "<<*(min_element(v.begin(),v.end(),[] (int a, int b)
  23.     {
  24.         int suma1=0,suma2=0;
  25.         while (a!=0)
  26.         {
  27.             suma1+=a%10;
  28.             a/=10;
  29.         }
  30.         while (b!=0)
  31.         {
  32.             suma2+=b%10;
  33.             b/=10;
  34.         }
  35.         if (suma1<suma2) return true;
  36.         return false;
  37.     }))<<endl;
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement