Advertisement
anhkiet2507

SAP XEP THEO CHU SO

Sep 12th, 2021
2,079
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6. using namespace std;
  7. int SoSanh(string X, string Y){
  8.     string XY = X.append(Y);
  9.     string YX = Y.append(X);
  10.     if(XY.compare(YX)>0){
  11.         return 1;
  12.     }
  13.     return 0;
  14. }
  15. void SapXep(vector<string>arr){
  16.     sort(arr.begin(), arr.end(), SoSanh);
  17.     for(int i = 0; i<arr.size(); i++){
  18.         cout << arr[i];
  19.     }
  20. }
  21. int main(){
  22.     int t;
  23.     cin >> t;
  24.     while(t--){
  25.         int n;
  26.         cin >> n;
  27.         string str;
  28.         vector<string> arr;
  29.         for(int i = 0; i<n; i++){
  30.             cin >> str;
  31.             arr.push_back(str);
  32.         }
  33.         SapXep(arr);
  34.         cout << endl;
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement