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

Code
// 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相关推荐

  1. 1198. Substring

    1198. Substring Description Dr lee cuts a string S into N pieces,s[1],-,s[N]. Now, Dr lee gives you ...

  2. Soj题目分类 python代码)

    正值期末复习,刷点soj放松下 但想看看能不能在找点关于数据结构的题目来做一下. 在网上看到有不少人上传过那些关于部分SOJ题目的描述,但是说实话有些乱 不过我看到有个网页中包含的一个类似文档的东西, ...

  3. 初学者acm的练习题指南

    上机练习题参考题 忘了在哪找的啦~~希望对大家有帮助呦 <!--[if !supportLists]-->1.    <!--[endif]-->Programming Bas ...

  4. sicily题目分类

    sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...

  5. [sicily]部分题目分类

    sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...

  6. Sicily 题目分类

    依照自己水平挑着做→ →~~ 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 ...

  7. 编程题目分类(剪辑)

    1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代 ...

  8. sicily1198

    1198. Substring Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Dr lee cuts a string ...

  9. 中大SICILY分类

    原文出处:http://linguifan2010.blog.163.com/blog/static/1315127442010102131322482/ ********************** ...

最新文章

  1. Linux crontab 命令基本说明
  2. 技术进阶:Kubernetes高级架构与应用状态部署
  3. HttpContext.Current.Session ,出现未将对象引用设置到实例上
  4. Android Bluetooth hci 命令分析
  5. 验证回文串Python解法
  6. C++字符串的不同存放类型 (string/char[])
  7. Linux 相关术语_002
  8. 关于离散数学的一点事情
  9. docker+阿里云镜像容器进行环境的备份与获取
  10. UML中依赖(Dependency)和关联(Association)之间的区别
  11. 铁血战士 (美国2018年沙恩·布莱克执导电影)
  12. CAN网络基础知识_20220727
  13. 树莓派python编程自学-树莓派Python编程指南 中文PDF扫描版
  14. Linux内存:内存管理的实质 (转CU上frank_seng 的总结,感谢frank_seng )
  15. 安装ADOBE READER时无法将数值写入键
  16. ElementUI导入Excel文件
  17. 百度智能云BCC云服务器释放实例
  18. 记一次hydra密码破解神器的学习
  19. 企业应如何选择服务器,既能节省成本又保证性能
  20. 【Spark深入学习 -10】基于spark构建企业级流处理系统

热门文章

  1. python解常微分方程(组)
  2. Java后端高频面试题集锦 1
  3. tcp_tw_reuse 为什么默认是关闭的?
  4. 运行DNW出现访问内存违例的问题解决
  5. 我们所以为的“云计算”
  6. 永磁同步电机(PMSM)最小损耗控制Simulink仿真
  7. 在佛山如何找到一个高质量的股票交易API平台?
  8. 合同诈骗罪中“一女多嫁”的诈骗认定
  9. go 调用winapi_Go调用Window SendARP() 方法
  10. 中兴C600 EPON配置