/*
1198. Substring 8个串排出最小字典序(8!枚举)
题目大意:
用N个字符串拼成一个新的字符串
要求新字符串字典序最小
如: a ab ac
则答案为:aabac
1<=N<=8,每个字符串长度不超过100
解题思路:
枚举n!种情况,最多为8!=40320种情况;
每枚举一种情况,与当前字典序最小字符串比较,如果字典序更小,则更新答案;
递归求解。
反例 ba b bab bba
重点注意
1.重点:学会使用sort函数 (#include <algorithm>)
2.重点:了解next_permutation();(#incluide <algorithm>)
*/
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
//1.重点:学会使用sort函数 (#include <algorithm>)
/*int cmp(string a,string b){
if((a+b)>(b+a))
return 0;
else
return 1;
}*/
bool cmp(string a , string b){
return (a+b)<(b+a);
}
int main(){
int T;
int N;
string a[8];
cin >> T;
for(int i=0;i<T;i++){
cin >> N;
if (N<=0) break;
for(int j=0;j<N;j++){
cin >> a[j];
}
//1.重点:学会使用sort函数 (#include <algorithm>)
sort(a,a+N,cmp);
for(int k=0;k<N;k++){
cout<<a[k];
}
cout << endl;
//system("pause");
}
}