Advertisement
sellmmaahh

prva-parc-2014-zad7-Raspon

Jul 30th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <deque>
  3. #include <algorithm>
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int Raspon (const int &n)
  10. { int pom{n};
  11. int max{pom%10}, min{pom%10};
  12. pom/=10;
  13. while (pom!=0) {
  14.     if (pom%10>max) max=pom%10;
  15.     if (pom%10<min) min=pom%10;
  16.     pom/=10;
  17. }
  18. return max-min;
  19. }
  20. int main () {
  21.  
  22. deque <int> dek(3);
  23. cout<<"Unesite elemente deka: ";
  24. for (int i=0; i<3; i++) cin>>dek[i];
  25.  
  26. sort(dek.begin(), dek.end(), [] (int x, int y) {if (Raspon(x)==Raspon(y)) return x>y; else return Raspon(x)>Raspon(y);});
  27. cout<<"Sortirano: ";
  28. for (auto x: dek) cout<<x<<" ";
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement