【PAT A-1038】Recover the Smallest Number
C++代码
#include <bits/stdc++.h>
using namespace std;
using gg = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
gg ni;
cin >> ni;
vector<string> v(ni);
for (auto& i : v) {
cin >> i;
}
sort(v.begin(), v.end(),
[](const string& s1, const string& s2) { return s1 + s2 < s2 + s1; });
string s = accumulate(v.begin(), v.end(), string());
auto i = find_if(s.begin(), s.end(), [](char c) { return c != '0'; });
i == s.end() ? (cout << "0") : (cout << s.substr(i - s.begin()));
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22