PAT 1038

python一行秒掉的题目

1 print int(''.join(sorted(raw_input().split()[1:], lambda s1, s2: cmp(s1+s2, s2+s1))))

其实这个题我不会... 原理还不明白,需要再学习一下

 1 #include <iostream>
 2 #include <vector>
 3 #include <string>
 4 #include <algorithm>
 5 
 6 using namespace std;
 7 
 8 struct Cmp{
 9     bool operator()(const string &s1, const string &s2){
10         return (s1 + s2) < (s2 + s1);
11     }
12 };
13 
14 int main(){
15     int N;
16     cin >> N;
17     
18     vector<string> nums(N);
19     for (int i = 0; i < N; i++)
20         cin >> nums[i];
21 
22     sort(nums.begin(), nums.end(), Cmp());
23 
24     string res;
25     for (int i = 0; i < nums.size(); i++)
26         res += nums[i];
27 
28     while (res[0] == '0')
29         res = res.substr(1, res.size() - 1);
30     if (res.size() == 0)
31         res = "0";
32 
33     cout << res << endl;
34 
35     return 0;
36 }
原文地址:https://www.cnblogs.com/EpisodeXI/p/4096119.html