Children's Game UVA

来源:互联网 发布:淘宝店铺怎么改折扣 编辑:程序博客网 时间:2024/06/03 18:20

贪心,主要是排序的方法,自己想了好久,没想出来,看了题解,恍然大悟,原来还能这样写,又新学到了一个技能点O(∩_∩)O哈哈~

#include<iostream>#include<algorithm>#include<string>#include<vector>#include<cstdio>using namespace std;string strs[55];bool cmp(string a, string b) {    return a + b > b + a;}int main() {    int n;    while(scanf("%d",&n) == 1 && n) {        for(int i = 0; i < n; ++i) {            cin >> strs[i];        }        sort(strs, strs + n, cmp);        for(int i = 0; i < n; ++i) {            cout << strs[i];        }        cout << endl;    }    return 0;}


原创粉丝点击