【sicily系列】 1198 substring

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


水题,做一个比较就可以了。比较A+B和B+A

 1 #include<iostream>
 2 #include<string>
 3 #include<vector>
 4 #include<algorithm>
 5 using namespace std;
 6 bool cmp (string a, string b) {
 7   return a + b > b + a;
 8 }
 9 int main() {
10   int t;
11   cin >> t;
12   while (t--) {
13   int n;
14   string a;
15   vector<string> q;
16   cin >> n;
17   while (n--) {
18     cin >> a;
19     q.push_back(a);
20   }
21   sort(q.begin(), q.end(), cmp);
22   while (!q.empty()) {
23     cout << q.back();
24     q.pop_back();
25   }
26   cout << endl;
27   }
28   return 0;
29 }                                 

时间: 2024-10-15 07:20:25

【sicily系列】 1198 substring的相关文章

Sicily 1198 Substring

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.

sicily 1198 substring 组合问题

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.

sicily 1198. Substring (递归全排列+排序)

DescriptionDr 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”},

天题系列:Substring with Concatenation of All Words

滑动窗口,但是很繁琐 public class Solution { public ArrayList<Integer> findSubstring(String S, String[] L) { //http://www.cnblogs.com/springfor/p/3872516.html ArrayList<Integer> res = new ArrayList<Integer>(); if(S==null || L==null || S.length()==

【sicily系列】1325 digit generator

Description For a positive integer N , the digit-sum of N is defined as the sum of N itself and its digits. When M is the digitsum of N , we call N a generator of M . For example, the digit-sum of 245 is 256 (= 245 + 2 + 4 + 5). Therefore, 245 is a g

(转)sicily题目分类

Sicily题目分类 ·         [数据结构/图论] 1310 Right-Heavy Tree   笛卡尔树相关,复杂度O(N)或O(NlogN). ·1426 Phone List         电话号码前缀检索,trie树相关. ·1443 Printer Queue      基本队列操作. ·1149 等价表达式         判断表达式是否等价(递归求解) ·1136 山海经             n长序列里求m次区间询问的最大连续子区间和.线段树/RMQ ·1252

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

天题系列 Minimum Window Substring

压力太大了,这道题先不做了 public class Solution { public String minWindow(String S, String T) { // 讲解http://articles.leetcode.com/2010/11/finding-minimum-window-in-s-which.html //代码 http://www.cnblogs.com/huntfor/p/3915288.html String res = ""; if(S==null |

【LeetCode刷题系列 - 003题】Longest Substring Without Repeating Characters

题目: Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: "bbbbb" Output: 1 Exp