Educational Codeforces Round 9 C

  这个题的意思是给你一些字符串, 按照一定的顺序重组这些字符串使得重组后的串的字典序最小, 考虑两个串的位置, 我们只需要按照a+b或者b+a中字典序较小的排列即可,代码如下:

#include <bits/stdc++.h>

using namespace std;
int n;
string s[50000 + 100];

bool cmp(const string &a, const string &b){
    return a+b < b+a;
}

int main() {
    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;
}
原文地址:https://www.cnblogs.com/xingxing1024/p/5305685.html