Advertisement
fahimkamal63

Largest number formed from array

May 7th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<vector>
  5. using namespace std;
  6. void show_vector(vector<string> s){
  7.     for(auto i = s.begin(); i < s.end(); i++){
  8.         cout << *i;
  9.     }
  10.     cout << endl;
  11. }
  12.  
  13. bool comp(string s1, string s2){
  14.     string s1s2 = s1+s2;
  15.     string s2s1 = s2+s1;
  16.     return (s1s2>s2s1);
  17. }
  18.  
  19. int main(){
  20.     int t; scanf("%d", &t);
  21.     while(t--){
  22.         int n; scanf("%d", &n);
  23.         vector<string> a;
  24.         for(int i = 0; i < n; i++){
  25.             string s; cin >> s;
  26.             a.push_back(s);
  27.         }
  28.         //show_vector(a);
  29.         sort(a.begin(), a.end(), comp);
  30.         show_vector(a);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement