Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created October 21, 2019 13:29
Show Gist options
  • Save surinoel/768a01c120b0b8205f269c458d28d612 to your computer and use it in GitHub Desktop.
Save surinoel/768a01c120b0b8205f269c458d28d612 to your computer and use it in GitHub Desktop.
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int arr[1000];
bool cmp(const int &u, const int &v) {
string a = to_string(u) + to_string(v);
string b = to_string(v) + to_string(u);
return a > b;
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n, cmp);
string ans = "";
for (int i = 0; i < n; i++) {
ans += to_string(arr[i]);
}
if (ans.length() > 1 && ans[0] == '0') {
ans = "0";
}
cout << ans << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment