//把数组排成最小的数


//把数组排成最小的数

#include "stdafx.h"
using namespace std;
#include <string>
#include <vector>
#include <map>
#include<algorithm>

class Solution
{
public:

    string find(vector<int> vec)
    {
        string sRet = "";
        int len = vec.size();
        if (len ==0)
        {
            return "";
        }
        //降序排序、、从大到小输出
        sort(vec.begin(), vec.end());
        // 321 32 3
        // 321 大于32 、--->(32132)--->如果反过来-->不降序排列-->得到32321-->这里 (32321> 32132)-->所以要降序排序
        for (int i = 0; i < len; i++)
        {
            sRet += to_string(vec[i]);
        }
        return sRet;
        // 321323

    }
    
    static bool cmp(int a, int b)
    {
        //从大到小排序
         return a > b;
        //先 返回最大值
        //string A = to_string(a) + to_string(b);
        //string B = to_string(b) + to_string(a);
        //return A < B;
    }

};


int main()
{

    vector<int> aa = { 1, 2, 3, 4, 5 };
    vector<int> bb = { 2, 3, 4, 5, 1 };
    vector<int>dd = { 4, 5, 1, 2, 3 };
    vector<int>cc = { 3, 32,321};

    Solution sou;
    sou.find(cc);
}

posted on 2020-04-19 17:02  心中日月007  阅读(107)  评论(0编辑  收藏  举报