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 ...
随机推荐
- IT服务(运维)管理实施的几个要点--第一章 IT服务质量的标准
子曰"干的最好就是个60分,稍有纰漏就是不及格" 谈一个事情,最先要谈的就是统一标准,又或者这个标准已经约定俗成,广泛认可,所以就可以略过.对于IT服务质量来说,确实有一个统一的标 ...
- python 字符串中的%s与format
你可以选择字符串拼接,你也可以选择使用%s或者是format,下面简单介绍一下它们的使用方法: # 在字符串后面跟%,然后后面加上要被替换的值 print('I like %s' % 'apples' ...
- vuejs实现本地数据的筛选分页
今天项目需要一份根据本地数据的筛选分页功能,好吧,本来以为很简单,网上搜了搜全是ajax获取的数据,这不符合要求啊,修改起来太费力气,还不如我自己去写,不多说直接上代码 效果图: 项目需要:点击左侧进 ...
- Linux_服务器_07_ 将用户设置为管理员
二.参考资料 1.CentOS普通用户获得管理员权限 2.linux下添加用户并赋予root权限
- 理解JavaScript原型
Javascript原型总会给人产生一些困惑,无论是经验丰富的专家,还是作者自己也时常表现出对这个概念某些有限的理解,我认为这样的困惑在我们一开始接触原型时就已经产生了,它们常常和new.constr ...
- SQLServer 索引总结
测试案例: SET STATISTICS IO ON SET STATISTICS TIME ON SET STATISTICS PROFILE ON SELECT count(A.CarrierT ...
- 关于SPF记录的说明
详细了解SPF记录的可以查看一下这篇博文:http://www.renfei.org/blog/introduction-to-spf.html 关于 SPF SPF:Sender Policy Fr ...
- flex盒模型 详细解析
flex盒模型 详细解析 移动端页面布局,采用盒模型布局,效果很好 /* ============================================================ ...
- ES6 Generators基本概念
ES6 Generators系列: ES6 Generators基本概念 深入研究ES6 Generators ES6 Generators的异步应用 ES6 Generators并发 在JavaSc ...
- Gson的学习与使用
Gson介绍: GSON是Google提供的用来在Java对象和JSON数据之间进行映射的Java类库.可以将一个Json字符转成一个Java对象,或者将一个Java转化为Json字符串. 特点: a ...