-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlab_7.cpp
47 lines (43 loc) · 815 Bytes
/
lab_7.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
void Sort(string X[], string Y[], int N)
{
pair <string, string> p[N];
for(long long int i = 0; i < N; i++)
{
p[i].first = X[i];
p[i].second = Y[i];
}
sort(p,p+N);
for(long long int i = 0; i < N; i++)
{
X[i]=p[i].first;
Y[i]=p[i].second;
}
}
int main()
{
int T;
cin>>T;
while(T--)
{
int N,Max=0; cin>>N;
string X[N],Y[N];
for(long long int i = 0; i < N; i++)
{
cin>>X[i];
if(Y[i].size()>Max) Max=X[i].size();
}
for(long long int i = 0; i < N; i++)
{
Y[i]=X[i];
while(Y[i].size() <= Max+1) Y[i]+=Y[i];
Y[i]=Y[i].substr(0,Max+1);
}
Sort(Y,X,N);
reverse(X,X+N);
for(long long int i = 0; i < N; i++) cout<<X[i];
cout<<endl;
}
return 0;
}