- 题目链接
- 灵光乍现,一开始写了很久的比较函数,后来在演草纸上写了两个数合并起来的样子得到的灵感。唉。。。看来敲代码是们艺术。
- AC code:
#include<iostream>
#include<algorithm>
using namespace std;
const int N=104;
string s[N];int n;
bool cmp(string a,string b){
if((a+b)>(b+a))return false;
else return true;
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
while(cin>>n){
for(int i=1;i<=n;i++)cin>>s[i];
sort(s+1,s+1+n,cmp);
for(int i=n;i>=1;i--)cout<<s[i];
cout<<endl;
}
}

本文介绍了一种通过合并字符串来优化比较函数的方法,该方法在解决特定字符串排序问题时展现出高效性。作者分享了从初步尝试到最终简洁实现的心路历程,并提供了完整的C++代码示例。
1625

被折叠的 条评论
为什么被折叠?



