1198 Substring
Substring
Time limit: 1 second(s) Memory limit: 32768 KBytes
Total Submit : 1767 Accepted Submit : 548
Problem
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
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
// 1198Substring.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
void sub_sort(string a[8],int N)
{
string temp;
for(int i=0;i<N;i++)
for(int j=i+1;j<N;j++)
{// 判断字符串大小,(a[i]+a[j])>(a[j]+a[i])表示判断"b""ba"这类情况
if((a[i]+a[j])>(a[j]+a[i]))
{
temp = a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int T; //测试案例数目
cin >> T;
int N; //字符串个数
for(int i=0; i<T; i++)
{
cin >> N;
string s[8] ;
for(int j=0; j<N; j++)
{
cin>>s[j];
}
sub_sort(s,N);
for(int j=0; j<N; j++)
{
cout<<s[j];
}
cout<<endl;
}
return 0;
}
转载于:https://www.cnblogs.com/sysuhekaifeng/archive/2008/12/22/1359648.html
1198 Substring相关推荐
- 1198. Substring
1198. Substring Description Dr lee cuts a string S into N pieces,s[1],-,s[N]. Now, Dr lee gives you ...
- Soj题目分类 python代码)
正值期末复习,刷点soj放松下 但想看看能不能在找点关于数据结构的题目来做一下. 在网上看到有不少人上传过那些关于部分SOJ题目的描述,但是说实话有些乱 不过我看到有个网页中包含的一个类似文档的东西, ...
- 初学者acm的练习题指南
上机练习题参考题 忘了在哪找的啦~~希望对大家有帮助呦 <!--[if !supportLists]-->1. <!--[endif]-->Programming Bas ...
- sicily题目分类
sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...
- [sicily]部分题目分类
sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...
- Sicily 题目分类
依照自己水平挑着做→ →~~ 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 ...
- 编程题目分类(剪辑)
1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代 ...
- sicily1198
1198. Substring Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Dr lee cuts a string ...
- 中大SICILY分类
原文出处:http://linguifan2010.blog.163.com/blog/static/1315127442010102131322482/ ********************** ...
最新文章
- Linux crontab 命令基本说明
- 技术进阶:Kubernetes高级架构与应用状态部署
- HttpContext.Current.Session ,出现未将对象引用设置到实例上
- Android Bluetooth hci 命令分析
- 验证回文串Python解法
- C++字符串的不同存放类型 (string/char[])
- Linux 相关术语_002
- 关于离散数学的一点事情
- docker+阿里云镜像容器进行环境的备份与获取
- UML中依赖(Dependency)和关联(Association)之间的区别
- 铁血战士 (美国2018年沙恩·布莱克执导电影)
- CAN网络基础知识_20220727
- 树莓派python编程自学-树莓派Python编程指南 中文PDF扫描版
- Linux内存:内存管理的实质 (转CU上frank_seng 的总结,感谢frank_seng )
- 安装ADOBE READER时无法将数值写入键
- ElementUI导入Excel文件
- 百度智能云BCC云服务器释放实例
- 记一次hydra密码破解神器的学习
- 企业应如何选择服务器,既能节省成本又保证性能
- 【Spark深入学习 -10】基于spark构建企业级流处理系统