Children's Game

来源:互联网 发布:淘宝手机p图教程视频 编辑:程序博客网 时间:2024/06/14 18:09

题意:

将输入的数串连成最大值。

思路:

直接按照字典集排序是不行的,比如99字典序小于991,但是99991大于99199,所以比较两个串相加后的字典序即可

代码:

#include<cstdio>#include<algorithm>#include<iostream>#include<cstring>#include<string>using namespace std;int cmp(string a, string b) {return a+b > b+a;}string s[55];int main() {int n;while(scanf("%d", &n) && 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