-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAshmal.cpp
More file actions
62 lines (55 loc) · 1.02 KB
/
Ashmal.cpp
File metadata and controls
62 lines (55 loc) · 1.02 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = 1e9 + 7;
int lexCompare(const string &a, const string &b)
{
int n = min(a.size(), b.size());
for (int i = 0; i < n; i++)
{
if (a[i] < b[i])
return -1;
else if (a[i] > b[i])
return 1;
}
// All characters matched so far
if (a.size() < b.size())
return -1;
else if (a.size() > b.size())
return 1;
else
return 0;
}
void solve(vector<string> arr)
{
int n = arr.size();
string ans;
for(int i = 0;i<n;i++)
{
if (arr[i] + ans < ans + arr[i])
ans = arr[i] + ans;
else
ans = ans + arr[i];
}
cout<<ans<<endl;
return;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<string> arr(n);
for (auto &a:arr)
cin>>a;
solve(arr);
}
return 0;
}