您的位置:首页 > 其它

UVA 10905 Children's Game

2014-07-25 16:22 357 查看
题目链接:点击打开链接

表示最近被高中生虐成渣了,不会正确的思考了。

这道题很有意思,之前就有小朋友问我。给一些正整数,按照一定是序列输出,使组成该数最大。。。表示,自己的思路很凌乱。还是看了别人的思路。

思路很有技巧:if(a + b > b + a) than a一定排在b前面。a + b是字符串是相加。。好思路。。弱渣只能继续学习。。!!

Code:

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

const int N = 55;

bool cmp (string a, string b){
    return a + b > b + a;
}

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