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

    天天向上
  • 相关阅读:
    华为内部面试题库(20)
    华为内部面试题库(18)
    华为内部面试题库(14)
    华为内部面试题库(12)
    华为内部面试题库(16)
    华为内部面试题库(17)
    华为内部面试题库(11)
    华为内部面试题库(13)
    Windows 危险的注册表键
    逆向工程师要学什么?
  • 原文地址:https://www.cnblogs.com/hg07/p/12732297.html
Copyright © 2011-2022 走看看