1198.Substring


Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

 

Dr lee cuts a string S into N pieces,s[1],…,s[N].   

Now, Dr lee gives you these N sub-strings: s[1],…s[N]. There might be several possibilities that the string S could be. For example, if Dr. lee gives you three sub-strings {“a”,“ab”,”ac”}, the string S could be “aabac”,”aacab”,”abaac”,…   

Your task is to output the lexicographically smallest S. 

 

Input

 

        The first line of the input is a positive integer T. T is the number of the test cases followed.   

The first line of each test case is a positive integer N (1 <=N<= 8 ) which represents the number of sub-strings. After that, N lines followed. The i-th line is the i-th sub-string s[i]. Assume that the length of each sub-string is positive and less than 100. 

 

Output

 

The output of each test is the lexicographically smallest S. No redundant spaces are needed. 

 

Sample Input

1
3
a
ab
ac

Sample Output

aabac

Problem Source

ZSUACM Team Member

tips:对于每两个字符串,就两种排序方式,比较其字典序即可,利用sort


#include
07. #include
08. #include
09. using namespace std;
10. int cmp(string a, string b)
11. {
12. /*
13. int a_len,b_len;
14. a_len=(int)a.size();
15. b_len=(int)b.size();
16. if (a_len>b_len)
17. {
18. for (int n=0;n
19. if (a==b) return 1;
20. }
21. else if (b_len>a_len)
22. {
23. for (int n=0;n
24. if (a==b) return 0;
25. }
26. */
27. return a+b
28. }
29. int input[1050];
30. int main()
31. {
32. int t;
33. scanf("%d",&t);
34. while (t--)
35. {
36. int N;
37. string tmp[10];
38. scanf("%d",&N);
39. for (int n=0;n> tmp[n];
40. sort(tmp,tmp+N,cmp);
41. string answer;
42. for (int n=0;n
43. cout << answer << endl;
44. }
45. return 0;
46. }

你可能感兴趣的:(Sicily,OJ)