洛谷-P1012 拼数

题目链接 思路: 【洛谷-P1012 拼数】虽然这只是个简单的排序,将每个数用字符串的形式输入,从大到小排并比较字典序即可,但是他的cmp函数用到了前几天思维碾压题的a+b与b+a的比较(hhh找题刚好遇到了,你说巧不巧)。
代码:

#include using namespace std; #define int long long #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); const int N=2e5+7; const int mod=1e9+7; const int inf=0x7fffffff; const double pi=3.1415926535; using namespace std; string s[25]; int n; bool cmp(string a,string b) { return a+b>b+a; } signed main() { IOS; cin>>n; for(int i=1; i<=n; i++) { cin>>s[i]; } sort(s+1,s+n+1,cmp); for(int i=1; i<=n; i++) { cout<[i]; } return 0; }

    推荐阅读