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 ...
随机推荐
- TBSchedule源码阅读1-TBScheduleManagerFactory
TBSchedule 1 TBScheduleManagerFactory 初始化 成员变量 ZKManager; IScheduleDataManager; Schedule ...
- 表转List泛型数组
转换那块怕忘记,留存一下 using System; using System.Collections.Generic; using System.Data; using System.Linq; u ...
- 26计算限制的异步操作01-CLR
由CLR via C#(第三版) ,摘抄记录... 异步优点:在GUI应用程序中保持UI可响应性,以及多个CPU缩短一个耗时计算所需的时间. 1.CLR线程池基础:为提高性能,CLR包含了代码来管理他 ...
- maven-tomcat7;IOC;AOP;数据库远程连接
[说明]真的是好烦下载插件啊,maven-tomcat7 插件试了好多次都不行,下载不成:部署不成:好不容易从github中得到的springmvc项目也是运行不起来,中间又是查了许多东西,绕着绕着都 ...
- python 写一个类似于top的监控脚本
最近老板给提出一个需要,项目需求大致如下: 1.用树莓派作为网关,底层接多个ZigBee传感节点,网关把ZigBee传感节点采集到的信息通过串口接收汇总,并且发送给上层的HTTP Serve ...
- Nginx教程
Nginx教程 1.背景 介绍 Nginx是一个高性能的HTTP服务器,以及反向代理服务器 组成 Ngnix有内核和模块组成.微结构的内核根据配置文件将一个请求映射到一个location块中,该loc ...
- cocoapods最新使用
1.首先用淘宝的Ruby镜像来访问CocoaPods,打开终端输入以下命令: (1)gem sources --remove http://ruby.gems.org/ (移除现有Ruby默认源) ...
- 低秩近似 low-rank approximation
- [IOI2018]组合动作
IOI2018 组合动作 UOJ 首先显然可以两次试出首字母 考虑增量构造 假设首字母为A,且已经试出前i个字母得到的串s 我们考虑press这样一个串s+BB+s+BX+s+BY+s+XA 首先这个 ...
- BZOJ1505: [NOI2004]小H的小屋
BZOJ1505: [NOI2004]小H的小屋 Description 小H发誓要做21世纪最伟大的数学家.他认为,做数学家与做歌星一样,第一步要作好包装,不然本事再大也推不出去. 为此他决定先在自 ...