https://leetcode.com/problems/largest-number/
Given a list of non negative integers, arrange them such that they form the largest number.
Example 1:
Input:[10,2]Output: "210"
Example 2:
Input:[3,30,34,5,9]Output: "9534330"
未提交代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n;
struct Node {
string s;
}node[maxn];
bool cmp(const Node& a, const Node& b) {
return a.s + b.s > b.s + a.s;
}
int main() {
scanf("%d", &n);
for(int i = 0; i < n; i ++)
cin >> node[i].s;
sort(node, node + n, cmp);
for(int i = 0; i < n; i ++)
cout << node[i].s;
return 0;
}