1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. bool cmp( int a, int b ) {
  8. return a > b;
  9. }
  10.  
  11.  
  12.  
  13. int main()
  14. {
  15. string broj;
  16. cin>>broj;
  17. int i=broj.length()-1;
  18. while (i>0){
  19.  
  20. char prethodni=broj[i];
  21. i--;
  22. char sljedeci=broj[i];
  23. while (prethodni>sljedeci){
  24. prethodni=sljedeci;
  25. i--;
  26. sljedeci=broj[i];
  27. }
  28. char karakteristika=sljedeci;
  29. for (int j=broj.length()-1;j>i;j--){
  30. if (broj[j]<karakteristika){ broj[i]=broj[j]; broj[j]=karakteristika; sort(broj.begin()+j,broj.end(),cmp); cout<< broj; return 0;}
  31. }
  32. }
  33. cout<<"Nema takvog";
  34. return 1;
  35. }
  36.