如果结果是0要输出0
#include <iostream> #include <vector> #include <algorithm> using namespace std; bool sortFunc(const string& s1, const string& s2){ return s1 + s2 < s2 + s1; } int main() { int N; cin>>N; vector<string> nums(N); string result = ""; for(int i = 0; i < N; i++) cin>>nums[i]; sort(nums.begin(), nums.end(), sortFunc); for (auto num:nums) result += num; while(result.length() > 0 && result[0] == '0') result.erase(0, 1); cout<<(result == "" ? "0" : result)<<endl; }