UVA - 10905 Children's Game

V_judge上的题目

         UVA - 10905 Children's Game

与PAT1038是一样的题目,或者说1038要稍微麻烦一点点,题解也可以通用,看到了就顺便做一下。

# include <cstdlib>
# include <string>
# include <iostream>
# include <algorithm>
using namespace std;
  

 bool cmp(const string& c1,const string& c2)
 {
	return c1 + c2 > c2 +c1; 
 }
int main()
{
	ios::sync_with_stdio(false);
	int i,j,k;
	int n;
	string str[55];
	while (cin>>n&&n)
	{
		for (i=0;i<n;i++)
			cin >> str[i];
		sort(str,str+n,cmp);
        string tmp;
		for (i=0;i<n;i++)
			tmp += str[i];
		cout << tmp << endl;
	}
    return 0;
}




你可能感兴趣的:(排序,贪心)