• //把数组排成最小的数



    //把数组排成最小的数

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

    天天向上
  • 相关阅读:
    一些概念理解(持续更新)
    python练习题
    linux常用命令
    数据库索引的一点学习(待更新)
    sql注入的一点学习(待更新)
    python 选择排序的实现
    python 冒泡排序的实现
    1--初始配置
    0--HttpUrlConnection 基础知识
    1--HTTP基础知识
  • 原文地址:https://www.cnblogs.com/hg07/p/12732297.html
Copyright © 2020-2023  润新知