@[Xialiang5](/space/show?uid=91823) 然而我不是神犇
by magical @ 2018-05-28 11:39:09
然而我是~~神犇~~
by MZMH @ 2018-05-28 12:17:49
**~~然而我只是大犇~~**
by 起名真的很难 @ 2018-05-28 12:33:13
你这个很容易举出反例
输入
2
321 32
正解应该是32321
但你这个是32132
by 起名真的很难 @ 2018-05-28 12:36:41
```cpp
typedef struct str{
char s[100];
bool operator <(const str& m)const{
return strcmp(s,m.s)>0;
}
};```
把这个重载变成
```cpp
bool cmp(string x,string y)
{
return x+y>y+x;
}
```
塞在sort里面应该就A了
**~~希望我早日成神犇~~**
by 起名真的很难 @ 2018-05-28 12:44:23
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
string a[10005];
int comp(string a,string b){
return a+b>b+a;
}
int main(int argc, char *argv[])
{
int n,i;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1,comp);
for(i=1;i<=n;i++)
cout<<a[i];
cout<<endl;
return 0;
}
```
by 郑yz @ 2018-05-28 12:45:22
给你介绍一下C++里面string的一种操作:
#### **假如string a=123,b=321,那么a+b=123321**
by 郑yz @ 2018-05-28 12:46:41
```cpp
#include<cstdio>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef struct str{
string s;
bool operator <(const str& m)const{
return s+m.s>m.s+s;
}
};
str st[30];
int main(){
int n,i;scanf("%d",&n);
for(i=0;i<n;i++)
cin>>st[i].s;
sort(st,st+n);
for(i=0;i<n;i++)
cout<<st[i].s;
return 0;
}
```
改了一下,过了
~~还是重载舒服,可以用快排~~
by diltraser @ 2018-05-28 14:39:16
@[郑yz](/space/show?uid=56665) 这里并不需要
by 2x6_81 @ 2018-07-25 16:25:21
@[2x6_81](/space/show?uid=89127) 不用也可以,但这样方便点
by 郑yz @ 2018-07-26 12:21:42