Advertisement
allia

большое число

Oct 18th, 2020 (edited)
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. void second_sort (string *arr, int n)
  9. {
  10.     for(int j = n-1; j >= 0; --j)
  11.         for(int i = 0; i < j; ++i)
  12.             if (arr[i+1]+arr[i] > arr[i]+arr[i+1])
  13.                 swap(arr[i], arr[i+1]);
  14. }
  15.  
  16. void first_sort (string *arr, int n)
  17. {
  18.    for (int i=1; i<n; ++i)
  19.       for (int j=0; j<n-i; j++)
  20.         if (arr[j].size() > arr[j+1].size())
  21.          swap (arr[j], arr[j+1]);
  22. }
  23.  
  24. int main()
  25. {
  26.   cout.flush();
  27.   int n = 0, index = 0;
  28.   cin >> n;
  29.  
  30.  string *arr = new string[n];
  31.   for (int i = 0; i<n; i++)
  32.   {
  33.     string buffer;
  34.     cin >> buffer;
  35.     arr[i] = buffer;
  36.   }
  37.  
  38. first_sort(arr, n);
  39. second_sort(arr, n);
  40.  
  41. for (int i = 0; i<n; i++)
  42.   {
  43.     cout << arr[i];
  44.   }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement