zoukankan      html  css  js  c++  java
  • //把数组排成最小的数


    //把数组排成最小的数

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

    天天向上
  • 相关阅读:
    linux下面发布80端口的服务
    visio 安装
    SSH进行登录远程主机,实验室网站,项目
    论文遇到的问题
    ubuntu设置目录容量大小
    ubuntu 磁盘分区
    SpringBoot打成的jar包发布,shell关闭之后一直在服务器运行
    docker的安装,使用
    多线程下载文件,ftp文件服务器
    抖音红人,
  • 原文地址:https://www.cnblogs.com/hg07/p/12732297.html
Copyright © 2011-2022 走看看