现在的位置: 首页 > 综合 > 正文

uva Children’s Game

2018年04月08日 ⁄ 综合 ⁄ 共 281字 ⁄ 字号 评论关闭

非常巧妙的题目,巧用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;
}

抱歉!评论已关闭.