pat 1038 Recover the Smallest Number (30分)
#include<iostream> #include<cstdio> #include<map> #include<set> #include<string> #include<algorithm> #include<vector> using namespace std; vector<string> vec; bool cmp(string a, string b) { return a + b < b + a; } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { string t; cin >> t; vec.push_back(t); } sort(vec.begin(), vec.end(), cmp); string ans = ""; for (int i = 0; i < n; i++) { ans += vec[i]; } // cout << ans << endl; int i = 0; while (ans[i] == '0') i++; int len = ans.size(); if (i >= len) { cout << 0 << endl; return 0; } for (; i < len; i++) { cout <<ans[i]; } cout <<endl; }