CodeForces 632 C.The Smallest String Concatenation(水~)
来源:互联网 发布:怎么检测网络是否正常 编辑:程序博客网 时间:2024/06/07 11:38
Description
给出n个字符串a1,…,an,将这n个字符串组合起来,问字典序最小的
Input
第一行一整数n表示字符串数量,之后n个串长不超过50的串,总串厂不超过5e4(1<=n<=5e4)
Output
输出字典序最小的组合方案
Sample Input
4
abba
abacaba
bcd
er
Sample Output
abacabaabbabcder
Solution
如果a+b < b+a说明a串必然在b串前面,按此规则给这n个串排个序依次输出即可
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 55555int n;string s[maxn];bool cmp(string a,string b){ return a+b<b+a;}int main(){ while(~scanf("%d",&n)) { for(int i=0;i<n;i++)cin>>s[i]; sort(s,s+n,cmp); for(int i=0;i<n;i++)cout<<s[i]; cout<<endl; } return 0;}
0 0
- CodeForces 632 C.The Smallest String Concatenation(水~)
- Codeforces 632C - The Smallest String Concatenation
- CodeForces-632C-The Smallest String Concatenation
- CodeForces 632C The Smallest String Concatenation
- CodeForces 632C The Smallest String Concatenation
- codeforces 632C C The Smallest String Concatenation(排序)
- Codeforces 632C The Smallest String Concatenation 【string】
- CodeForces 632C C. The Smallest String Concatenation
- codeforces--623C The Smallest String Concatenation
- codeforces 632C The Smallest String Concatenation【巧妙的排序】
- CodeForces 632C The Smallest String Concatenation 排序
- codeforces 632C The Smallest String Concatenation 排序
- The Smallest String Concatenation CodeForces 632C 字符串
- The Smallest String Concatenation CodeForces
- The Smallest String Concatenation CodeForces
- Codeforce 632C The Smallest String Concatenation
- C. The Smallest String Concatenation
- Educational Codeforces Round 9 -- C - The Smallest String Concatenation
- cocos2D文档的使用 2
- PHP获取当前文件路径信息的方法
- 设计模式C++实现(3)——适配器模式
- Android用surface直接显示yuv数据
- 第八章 8-2 数字时钟
- CodeForces 632 C.The Smallest String Concatenation(水~)
- 设计模式C++实现(4)——单例模式
- 大数据生态
- 使用vitaimo搭建可以播放组播流的播放器
- 设计模式C++实现(5)——原型模式、模板方法模式
- Druid的简介及功能
- NS3 使用可视化工具PyViz
- 二叉树中和为某一值的路径(Java实现)
- emoji无法插入数据库问题