Uva 10905 Children's Game

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 struct st{
 5     string s;
 6 };
 7 st f[100];
 8 
 9 bool cmp(st a,st b)
10 {
11     return a.s + b.s > b.s + a.s;
12 }
13 
14 int main()
15 {
16     int n;
17     while(cin >> n)
18     {
19         for(int i = 0;i < 100;i++) f[i].s.clear();
20         if(!n) break;
21         for(int i = 1;i <= n; i++) cin >> f[i].s;
22         sort(f+1,f+n+1,cmp);
23         for(int i = 1;i <= n;i++)
24             cout << f[i].s;
25         cout << endl;
26     }
27 }

 

题意:给n个数,一一连接,输出能连接出的最大的数

坑点:字典序排序是错的,反例 999 999911 显然前面这个在前面最优

题解:假设a,b两个串,他们只要连接,要么a+b大要么b+a大,所以,以此排序

代码:

 

posted on 2015-11-23 22:39  小松song  阅读(93)  评论(0)    收藏  举报

导航