The Smallest String Concatenation

题目链接:http://codeforces.com/problemset/problem/632/C

    ——每天在线,欢迎留言谈论。

题目大意:

给你n个字符串,相加后 字典序最小

思路:

只需要保证每个相邻的两个字符串组合后 s1+s2>s2+s1 即可。

用sort()快速排序,最后依次输出即可!

AC代码:

 #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int MAXN=5e4+;
string ss[MAXN];
bool cmp(string s1,string s2)
{
return s1+s2<s2+s1;
}
int main()
{
int n;
cin>>n;
for(int i=;i<n;i++)
cin>>ss[i];
sort(ss,ss+n,cmp);
for(int i=;i<n;i++)
cout<<ss[i];
cout<<endl;
return ;
}

2017-05-07 19:20:25

codeforces 632C The Smallest String Concatenation的更多相关文章

  1. CodeForces 632C The Smallest String Concatenation//用string和sort就好了&&string的基础用法

    Description You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them togethe ...

  2. codeforces 632C. The Smallest String Concatenation 排序

    题目链接 给出n个字符串, 将他们连在一起, 求连玩之后字典序最小的那种情况. 按a+b<b+a排序.... #include <iostream> #include <vec ...

  3. codeforces 632C C. The Smallest String Concatenation(sort)

    C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...

  4. Educational Codeforces Round 9 C. The Smallest String Concatenation 排序

    C. The Smallest String Concatenation 题目连接: http://www.codeforces.com/contest/632/problem/C Descripti ...

  5. Educational Codeforces Round 9 C. The Smallest String Concatenation —— 贪心 + 字符串

    题目链接:http://codeforces.com/problemset/problem/632/C C. The Smallest String Concatenation time limit ...

  6. Educational Codeforces Round 9 C. The Smallest String Concatenation(字符串排序)

    You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them together in some or ...

  7. C. The Smallest String Concatenation

    C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...

  8. C. The Smallest String Concatenation-C++sort排序~~

    C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...

  9. Effective Java 51 Beware the performance of string concatenation

    Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic ...

随机推荐

  1. [Shell]sed命令在MAC和Linux下的不同使用方式

    ---------------------------------------------------------------------------------------------------- ...

  2. JavaScript高级编程(1)——JavaScript初识

    一.javascript的简介 1.1 javascript的历史回顾. Javascript诞生于1995年.当时,它主要的目的是用来处理一些由服务器端处理的输入验证操作.在javascript没有 ...

  3. SpringCloud2.0入门3-新的eureka依赖

    前言 Springboot2.0推出有一段时间了,是要学习1.5+还是从2.0开始?犹豫的原因是资料不全,目前现有的资料大部分是1.0的.但作为学习者,肯定要学习最新的.不如,先试试. 搭建Eurek ...

  4. 机器学习中数据清洗&预处理

    数据预处理是建立机器学习模型的第一步,对最终结果有决定性的作用:如果你的数据集没有完成数据清洗和预处理,那么你的模型很可能也不会有效 第一步,导入数据 进行学习的第一步,我们需要将数据导入程序以进行下 ...

  5. vue-router 基本使用

    参考原文:http://www.cnblogs.com/SamWeb/p/6610733.html 此链接讲了大部分常用的路由配置及使用,下星期总结

  6. 服务注册中心之ZooKeeper系列(三) 实现分布式锁

    通过ZooKeeper的有序节点.节点路径不回重复.还有节点删除会触发Wathcer事件的这些特性,我们可以实现分布式锁. 一.思路 zookeeper中创建一个根节点Locks,用于后续各个客户端的 ...

  7. 基于SpringMVC+Spring+MyBatis实现秒杀系统【数据库接口】

    前言 该篇教程主要关注MyBatis实现底层的接口,把MyBatis交给Spring来托管.数据库连接池用的c3p0.数据库用的MySQL.主要有2个大类:秒杀商品的查询.秒杀明细的插入. 准备工作 ...

  8. 南大算法设计与分析课程OJ答案代码(3)

    问题 A: 动态中位数问题 时间限制: 1 Sec  内存限制: 8 MB提交: 866  解决: 102提交 状态 算法问答 题目描述 输入一组整数a1, a2, …, an ,每输入一个整数,输出 ...

  9. html5入门:教你用canvas写一个时钟

    今天的时间比较充裕,心血来潮,为大家分享一个html5的小例子,希望对刚学html5或者是没学html5正准备学的“童鞋们”展示一个小案例,希望对你们的学习有帮助!高手嘛!请跳过吧! 好了,闲话少数, ...

  10. Thread类(线程)

    操作系统通过线程对程序的执行进行管理,当操作系统运行一个程序的时候,首先,操作系统将为这个准备运行的程序分配一个进程,以管理这个程序所需要的各种资源.在这些资源之中,会包含一个称为主线程的线程数据结构 ...