codeforces 632C C. The Smallest String Concatenation(sort)
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
题意:给你n个字符串,输出字典序最小的排序;
思路:写个比较函数cmp(),sort一下再输出就好了;
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int N=1e4+4;
string str[6*N];
int n;
int cmp(string x,string y)
{
return x+y<y+x;
}
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
cin>>str[i];
}
sort(str,str+n,cmp);
for(int i=0;i<n;i++)
{
cout<<str[i];
}
return 0;
}
codeforces 632C C. The Smallest String Concatenation(sort)的更多相关文章
- 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 ...
- codeforces 632C The Smallest String Concatenation
The Smallest String Concatenation 题目链接:http://codeforces.com/problemset/problem/632/C ——每天在线,欢迎留言谈论. ...
- Educational Codeforces Round 9 C. The Smallest String Concatenation 排序
C. The Smallest String Concatenation 题目连接: http://www.codeforces.com/contest/632/problem/C Descripti ...
- 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 ...
- C. The Smallest String Concatenation
C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...
- C. The Smallest String Concatenation-C++sort排序~~
C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...
- codeforces 632C. The Smallest String Concatenation 排序
题目链接 给出n个字符串, 将他们连在一起, 求连玩之后字典序最小的那种情况. 按a+b<b+a排序.... #include <iostream> #include <vec ...
- [Swift]LeetCode988. 从叶结点开始的最小字符串 | Smallest String Starting From Leaf
Given the root of a binary tree, each node has a value from 0 to 25 representing the letters 'a' to ...
随机推荐
- python实现身份证识别
github: 人脸联合语音身份认证:https://github.com/tsstss123/faceUnionVoiceRecognition 身份证识别简易版:https://github.co ...
- DICOM:C-GET服务
背景: 之前博文对照过多次C-MOVE与C-GET服务的差别,两者最大的差别在于C-GET是基于单个TCP连接的点对点的双方服务.而C-MOVE是基于两个TCP连接的三方服务(详情參见:<DIC ...
- java.lang.IllegalStateException: ImageView no longer exists. You should not use this PhotoViewAttacher any more.
java.lang.IllegalStateException: ImageView no longer exists. You should not use this PhotoViewAttach ...
- webview300毫秒点击问题
http://www.jshacker.com/note/3585 http://blog.csdn.net/zfy865628361/article/details/49512095 http:// ...
- 我的Android进阶之旅------>Android字符串资源中的单引号问题error: Apostrophe not preceded by 的解决办法
刚刚在string字符串资源文件中,写了一个单引号,报错了,错误代码如下 error: Apostrophe not preceded by \ (in OuyangPeng's blog ) 资源文 ...
- python3 计算文件夹中所有py文件里面代码行数,注释行数,空行数
import os,re #代码所在位置 FILE_PATH = './' def analyze_code(codefilesource): ''' 打开一个py文件统计其中的代码行数,包括空格和注 ...
- C#自己写的第一个小程序,庆祝一下
Packages.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; na ...
- 找到最大或最小的N个值
对于python原生的数据类型来说,并不存在直接的方法可以找到最大或最小的N个值, 传统的方法必须先排序,然后再截取相应的值,而且对于集合这类数据类型来说还不能直接排序, 需要先转化为列表才行,有的时 ...
- ZOJ - 1505 Solitaire 【双向BFS】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1505 题意 一个8 * 8 的棋盘上面有四个棋子 棋子可以上下左 ...
- ssh允许root用户登陆
新的系统无root用户密码,设置root用户密码,修改也是这么修改 sudo passwd root 连续输入两次新密码. 允许root用户登陆: /etc/ssh/sshd_config 找到 Pe ...