Advertisement
krylovilya

Untitled

Nov 19th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int sort(int x)
  6. {
  7.     int y, z;
  8.     y = x % 10;
  9.     x /= 10;
  10.     while (x != 0)
  11.     {
  12.         if (x % 10 >= y % 10)
  13.             y = y * 10 + x % 10;
  14.         else
  15.         {
  16.             z = 0;
  17.             while (x % 10 < y % 10 && y > 0)
  18.             {
  19.                 z = z * 10 + y % 10;
  20.                 y /= 10;
  21.             }
  22.             y = y * 10 + x % 10;
  23.             while (z != 0)
  24.             {
  25.                 y = y * 10 + z % 10;
  26.                 z /= 10;
  27.             }
  28.         }
  29.         x /= 10;
  30.     }
  31.     return y;
  32. }
  33.  
  34. int main()
  35. {
  36.     setlocale(LC_ALL, "Russian");
  37.     int x;
  38.     cout << "Введите число: ";
  39.     cin >> x;
  40.     x = sort(x);
  41.     cout << endl << "результат: " << x << endl;
  42.     system("pause");
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement