1038 Recover the Smallest Number(自定义排序)

题意:给定一些字符串,将这些字符串按一定顺序排列拼接成一个字符串,求能够拼接成的字典序最小的字符串。

思路:对比两个字符串a,b,将这两个字符串尝试拼接起来成ab与ba,如果ab

#include
using namespace std;

int main(){
    vectorres;
    int n;cin>>n;
    for(int i=0;i>str;
        res.push_back(str);
    }
    sort(res.begin(),res.end(),[](auto&a,auto&b){
        //排序函数
        string ab=a;ab+=b;
        string ba=b;ba+=a;
        if(ab!=ba)
        return ab

你可能感兴趣的:(pat,算法,c++,数据结构)