设有n个正整数,将他们连接成一排,组成一个最大的多位整数。 如:
作者:
蒜苗爱妞妞 | 来源:发表于
2018-05-12 17:01 被阅读0次#include<iostream>
#include<vector>
#include<string>
using namespace std;
class Solution {
public:
void sort(vector<string> &str_array) {
int len = str_array.size();
for (int i = 0; i < len - 1; i++) {
for (int j = 0; j < len - 1 - i; j++) {
if ((str_array[j] + str_array[j + 1]) < (str_array[j+1] + str_array[j]))
swap(str_array[j], str_array[j + 1]);
}
}
}
};
int main() {
int tmp;
while (cin >> tmp) {
vector<string> str_array;
string str;
for (int i = 0; i < tmp; i++) {
cin >> str;
str_array.push_back(str);
}
Solution s;
s.sort(str_array);
for (int i = 0; i < str_array.size(); i++) {
cout << str_array[i];
}
cout << endl;
}
return 0;
}
本文标题:设有n个正整数,将他们连接成一排,组成一个最大的多位整数。 如:
本文链接:https://www.haomeiwen.com/subject/umrhdftx.html
网友评论