#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
bool Compare(int a, int b)
{
string A = to_string(a) + to_string(b);
string B = to_string(b) + to_string(a);
return (A < B);
}
int PrintMinNumber(vector<int> numbers)
{
int length = numbers.size();
if (length <= 0)
{
return 0;
}
else
{
string str;
sort(numbers.begin(), numbers.end(), Compare);
for (int i = 0; i < length; ++i)
{
str += to_string(numbers[i]);
}
return stoi(str);
}
}
int main()
{
vector<int> vec;
vec.push_back(14);
vec.push_back(23);
vec.push_back(4);
vec.push_back(2);
cout << PrintMinNumber(vec) << endl;
return 0;
}
【C++代码】整形数组所能组成的最小数
最新推荐文章于 2024-05-10 08:29:46 发布