您的位置:首页 > 其它

UVa 10905 Children's Game / 贪心

2013-12-06 20:05 417 查看
给你n个数字 求一个组合 使n个数字按顺序组成的数最大 贪心 排序输出即可

#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
string a[100];

bool cmp(string a,string b)
{
	string s1,s2;
	s1 = a+b;
	s2 = b+a;
	return s1 > s2;
}
int main()
{
	int i,n;
	while(scanf("%d",&n),n)
	{
		for(i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		sort(a,a+n,cmp);
		string s;
		for(i = 0;i < n; i++)
		{
			s += a[i];
			//cout << a[i] << endl;
		}
		cout << s << endl;
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: