| Time Limit: | 1000MS | Memory Limit: | 65536KB |
|---|---|---|---|
| Total Submissions: | 493 | Accepted: | 188 |
Description:
不知大家是否玩过数字接龙的游戏,给你n个数字,将这n个数字连接在一起成一个数字,数字大者为胜。
我想会编程的你一定发现了,你每次都可以赢的,那么现在就来试试吧!
Input:
输入多组测试数据,每组数据第一行是一个正整数n(1≤n≤10)。接下来n行每行一串字符串,长度不大于10 。
Output:
每个测试数据输出一行,就是n串字符串连接成一串中字典序最大的那一串。
Sample Input:
2
123
456
3
ba
b
bab
Sample Output:
456123
bbabba
Source:
#include<iostream>
#include<cstdio>
#include <string>
#include <algorithm>
using namespace std;
typedef long long LL;
string str[15];
int alen,blen;
bool cmp( string a,string b)
{
string c = a+b;
string d = b+a;
return c>d;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for( int i = 0;i <n;++i)
cin>>str[i];
sort(str,str+n,cmp);
for( int i = 0;i <n;++i)
cout<<str[i];
puts("");
}
return 0;
}
\