CodeForces 632C The Smallest String Concatenation//用string和sort就好了&&string的基础用法

时间:2022-09-15 10:23:36
Description

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.

Input

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.

Output

Print the only string a — the lexicographically smallest string concatenation.

Sample Input

Input
4
abba
abacaba
bcd
er
Output
abacabaabbabcder
Input
5
x
xx
xxa
xxaa
xxaaa
Output
xxaaaxxaaxxaxxx
Input
3
c
cb
cba
Output
cbacbc

题意:给你一些字符串,把字符串重新组合有很多种情况,把字典序最小的那种情况输出
思路:首先肯定是不能按照单个字符串的字典序排序然后从小到大输出,因为x的字典序肯定要比aa小,但是输出肯定是aax,这个时候只要用string,比较两两字符串联之后的字典序排序输出就行,stl真是强大。。。
 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
struct node
{
string str; };
node str1[];
bool cmp(node a,node b)
{
return a.str+b.str<b.str+a.str;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++)
{
cin>>str1[i].str;
}
sort(str1+,str1++n,cmp);
for(int i=;i<=n;i++)
cout<<str1[i].str;
printf("\n");
}
return ;
}

这个时候说一下string的用法

注意是#include <string>而不是#include <cstring>

a)    string s;  //生成一个空字符串s
b)    string s(str) //拷贝构造函数 生成str的复制品
c)    string s(str,stridx) //将字符串str内“始于位置stridx”的部分当作字符串的初值
d)    string s(str,stridx,strlen) //将字符串str内“始于stridx且长度顶多strlen”的部分作为字符串的初值
e)    string s(cstr) //将C字符串作为s的初值
f)    string s(chars,chars_len) //将C字符串前chars_len个字符作为字符串s的初值。
g)    string s(num,c) //生成一个字符串,包含num个c字符
h)    string s(beg,end) //以区间beg;end(不包含end)内的字符作为字符串s的初值
i)    s.~string() //销毁所有字符,释放内存

2.字符串操作函数
a) =,assign()   //赋以新值
b) swap()   //交换两个字符串的内容
c) +=,append(),push_back() //在尾部添加字符
d) insert() //插入字符
e) erase() //删除字符
f) clear() //删除全部字符 
g) replace() //替换字符
h) + //串联字符串
i) ==,!=,<,<=,>,>=,compare()  //比较字符串
j) size(),length()  //返回字符数量
k) max_size() //返回字符的可能最大个数
l) empty()  //判断字符串是否为空
m) capacity() //返回重新分配之前的字符容量
n) reserve() //保留一定量内存以容纳一定数量的字符
o) [ ], at() //存取单一字符
p) >>,getline() //从stream读取某值
q) <<  //将谋值写入stream
r) copy() //将某值赋值为一个C_string
s) c_str() //将内容以C_string返回
t) data() //将内容以字符数组形式返回
u) substr() //返回某个子字符串
v)查找函数
w)begin() end() //提供类似STL的迭代器支持
x) rbegin() rend() //逆向迭代器
y) get_allocator() //返回配置器

CodeForces 632C The Smallest String Concatenation//用string和sort就好了&&string的基础用法的更多相关文章

  1. codeforces 632C The Smallest String Concatenation

    The Smallest String Concatenation 题目链接:http://codeforces.com/problemset/problem/632/C ——每天在线,欢迎留言谈论. ...

  2. codeforces 632C&period; The Smallest String Concatenation 排序

    题目链接 给出n个字符串, 将他们连在一起, 求连玩之后字典序最小的那种情况. 按a+b<b+a排序.... #include <iostream> #include <vec ...

  3. 用java8重写Arrays&period;sort&lpar;oldWay&comma; new Comparator&lt&semi;String&gt&semi;&lpar;&rpar;&lbrace;&commat;Override public int compare&lpar;String s1&comma; String s2&rpar;&rcub;&rpar;&semi;

    参考https://www.liaoxuefeng.com/article/001411306573093ce6ebcdd67624db98acedb2a905c8ea4000/ Java 8终于引进 ...

  4. codeforces 632C C&period; The Smallest String Concatenation&lpar;sort&rpar;

    C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...

  5. Educational Codeforces Round 9 C&period; The Smallest String Concatenation 排序

    C. The Smallest String Concatenation 题目连接: http://www.codeforces.com/contest/632/problem/C Descripti ...

  6. Educational Codeforces Round 9 C&period; The Smallest String Concatenation —— 贪心 &plus; 字符串

    题目链接:http://codeforces.com/problemset/problem/632/C C. The Smallest String Concatenation time limit ...

  7. Educational Codeforces Round 9 C&period; 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 ...

  8. C&period; The Smallest String Concatenation

    C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...

  9. Effective Java 51 Beware the performance of string concatenation

    Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic ...

随机推荐

  1. &lbrack;速记!vs调试技巧&rsqb;

    当程序崩溃却又没有报错的时候,进入调试程序,断点处按Alt+7可以进入函数调用栈,甚至可以进入汇编栈,真的很有用,以后有时间学习汇编的话,估计这个功能会更加强大!

  2. python环境搭建-Linux系统下python2&period;6&period;6升级python3&period;5&period;2步骤

    [root@template ~]# python -v # /usr/lib64/python2.6/encodings/utf_8.pyc matches /usr/lib64/python2.6 ...

  3. nginx-gridfs使用

    安装nginx及nginx-gridfs 依赖库.工具   # yum -y install pcre-devel openssl-devel zlib-devel # yum -y install ...

  4. 基于RDBMS的BI设计

    ================================ 都说BI,什么OLAP,什么ROLAP,MOLAP,但是如何基于RDBMS实现,基本都不怎么说. 怎么做的: 1.通过多维分析模型,存 ...

  5. linux c 生成uuid

    /********方法一**********/#include <stdio.h> #include <stdlib.h> #include <string.h> ...

  6. Qt:基于TCP和UDP的局域网P2P(局域网)通讯封装

    封装了一个类,可以进行在局域网进行P2P通讯(仅局域网可用) 也就是说,假设局域网中有10台电脑,那么从本机发出的数据,将依次派发到这10台电脑(目前的设计中包括自己这台) 在使用方面,构造的时候给端 ...

  7. Oracle之range&comma;hash&comma;list分区现实应用及优缺点汇总

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp51 [align=center;] Oracle之range,hash,l ...

  8. 网络编程之套接字(tcp)

    经过几天高强度的学习,对套接字的编程有了初步的认识,今天对这几天所学的知识总结一下:首先简单阐述一下tcp通信: TCP提供的是可靠的,顺序的,以及不会重复的数据传输,处理流控制,由于TCP是可靠的, ...

  9. 基于多进程和基于多线程服务器的优缺点及nginx服务器的启动过程

    基于多进程服务器的优点: 1.由操作系统进行调度,运行比较稳定强壮 2.能够方便地通过操作系统进行监控和管理 例如对每个进程的内存变化状况,甚至某个进程处理什么web请求进行监控.同时可以通过给进程发 ...

  10. JS-Object&lpar;3&rpar; 继承&lpar;prototype方式, 类方式&rpar;; javascript6的知识(部分)

    原型方式的继承 创建child object classes(constructors) , 子类如何从父类中继承特性. 原型链继承prototypal inheritance (ruby中的继承也是 ...