码迷,mamicode.com
首页 > 编程语言 > 详细

//把数组排成最小的数

时间:2020-04-19 17:57:25      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:--   solution   ++   bool   nbsp   把数组排成最小的数   vector   namespace   public   


//把数组排成最小的数

#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);
}

//把数组排成最小的数

标签:--   solution   ++   bool   nbsp   把数组排成最小的数   vector   namespace   public   

原文地址:https://www.cnblogs.com/hg07/p/12732297.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!