输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。例如,输入数组{3,32,321},则打印出这三个数字能排成的最小数字321323。
struct comp {
int operator()(string num1, string num2)
{
string str1 = num1 + num2;
string str2 = num2 + num1;
return str1.compare(str2);
}
};
void min_num(vector<string>::iterator beg, vector<string>::iterator end)
{
sort(beg, end, comp());
copy(beg, end, ostream_iterator<string>(cout, ""));
}