首页 > 代码库 > uva Children's Game

uva Children's Game

非常巧妙的题目,巧用cmp,注意cmp的重载

#include <iostream>
#include <algorithm>
using namespace std;
string a[55];
bool cmp(string a, string b){
    return a+b > b+a;
}
int main(int argc, char const *argv[])
{
    int n;
    while(cin >> n && n){
      for(int i = 0; i < n; i++)
        cin >> a[i];
      sort(a,a+n,cmp);
      for(int i = 0; i < n; i++)
        cout << a[i];
      cout << endl;
    }
    return 0;
}