By
yusijia
Updated:
Contents
题目:
输入n代表个数,将他们排列成一排使组合出来的数最大
例如:
2
121 12
12121
//a + b > b + a ? a + b : b + a;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <vector> #include <string>
using namespace std;
int main() { int n; string strs[3];
scanf("%d", &n);
for(int i = 0; i < n; i++){ cin >> strs[i]; }
sort(strs, strs + n);
string result;
for(int i = 0; i < n - 1; i++){ result = strs[i] + strs[i + 1] > strs[i + 1] + strs[i] ? strs[i] + strs[i + 1] : strs[i + 1] + strs[i + 1]; if(i == n - 2) break; }
cout << result;
return 0; }
|