C. The Smallest String Concatenation
3 seconds
256 megabytes
standard input
standard output
You're given a list of n strings
a1, a2, ..., an. You'd like to concatenate them together in some order such that the resulting string would be lexicographically
smallest.
Given the list of strings, output the lexicographically smallest concatenation.
The first line contains integer n — the number of strings (1 ≤ n ≤ 5·104).
Each of the next n lines contains one string
ai (1 ≤ |ai| ≤ 50) consisting of only lowercase English letters. The sum of string lengths will not
exceed 5·104.
Print the only string a — the lexicographically smallest string concatenation.
4
abba
abacaba
bcd
er
abacabaabbabcder
5
x
xx
xxa
xxaa
xxaaa
xxaaaxxaaxxaxxx
3
c
cb
cba
cbacbc
字符串排序
#include <bits/stdc++.h>
using namespace std; typedef long long int llint;
const int maxn = 5e4+100;
string a[maxn]; int cmp(const string &a, const string &b) {
return a + b < b + a;
} int main() {
int n;
scanf("%d",&n);
for (int i = 0; i<n; i++) cin >> a[i];
sort(a, a+n, cmp);
for (int i = 0; i<n; i++) cout << a[i];
cout << endl;
return 0;
}
C. The Smallest String Concatenation的更多相关文章
- codeforces 632C The Smallest String Concatenation
The Smallest String Concatenation 题目链接:http://codeforces.com/problemset/problem/632/C ——每天在线,欢迎留言谈论. ...
- 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 ...
- Educational Codeforces Round 9 C. The Smallest String Concatenation 排序
C. The Smallest String Concatenation 题目连接: http://www.codeforces.com/contest/632/problem/C Descripti ...
- 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 ...
- Educational Codeforces Round 9 C. The Smallest String Concatenation —— 贪心 + 字符串
题目链接:http://codeforces.com/problemset/problem/632/C C. The Smallest String Concatenation time limit ...
- 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 ...
- codeforces 632C. The Smallest String Concatenation 排序
题目链接 给出n个字符串, 将他们连在一起, 求连玩之后字典序最小的那种情况. 按a+b<b+a排序.... #include <iostream> #include <vec ...
- C. The Smallest String Concatenation-C++sort排序~~
C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...
- Effective Java 51 Beware the performance of string concatenation
Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic ...
随机推荐
- Java I/O---序列化接口Serializable
1.JDK API 中关于Serializable的描述 public interface Serializable 类通过实现 java.io.Serializable 接口以启用其序列化功能.未实 ...
- vs发布项目webconfig替换语法
关于vs发布项目时webconfig替换语法也是最近才学到的东西,写这篇文章就当是作个备忘录吧,如果能帮助别人能够学习到webconfig如何替换那就再好不过了. 1.认识一下web项目下的web.D ...
- [置顶]
MVC输出缓存(OutputCache参数详解)
1.学习之前你应该知道这些 几乎每个项目都会用到缓存,这是必然的.以前在学校时做的网站基本上的一个标准就是1.搞定增删改查2.页面做的不要太差3.能运行(ps真的有这种情况,答辩验收的时候几个人在讲台 ...
- 为什么说Python 是大数据全栈式开发语言
欢迎大家访问我的个人网站<刘江的博客和教程>:www.liujiangblog.com 主要分享Python 及Django教程以及相关的博客 交流QQ群:453131687 原文链接 h ...
- Python个人项目--豆瓣图书个性化推荐
项目名称: 豆瓣图书个性化推荐 需求简述:从给定的豆瓣用户名中,获取该用户所有豆瓣好友列表,从豆瓣好友中找出他们读过的且评分5星的图书,如果同一本书被不同的好友评5星,评分人数越多推荐度越高. 输入: ...
- Tengine 安装配置全过程(nginx 同理)
1.安装必要的编译环境好 yum update yum install gcc gcc-c++ autoconf automake 2.安装需要的组件 A.PCRE PCRE(Perl Compati ...
- PHP生成验证码
<?php check_code(); function check_code($width = 100, $height = 50, $num = 4, $type = 'jpeg') { $ ...
- mayavi安装
Mayavi是python的一个包,提供方便的可视化方案.目前(20150809)Mayavi还没有py3的支持,以下安装环境在python 2.7.10下进行 安装Mayavi: 1. 通过pip ...
- SpringMVC @SessionAttributes注解
@SessionAttributes 注解只能作用到类上 @SessionAttributes(value={"user"},types={String.class}) @Sess ...
- Nginx集群之.Net打造WebApp(支持IOS和安卓)
目录 1 大概思路... 1 2 Nginx集群之.Net打造WebApp(支持IOS和安卓) 1 3 安卓模拟器... 1 4 MUI框架... 3 ...