uva10905

简介: 题意:给定n个数字字符串,求他们能组成的最大数字字符串。 做法:用,cmp比较函数比较s+t与t+s即可。 代码: #include #include #include #include #include #define zz using namespace st...

题意:给定n个数字字符串,求他们能组成的最大数字字符串。

做法:用<string>,cmp比较函数比较s+t与t+s即可。


代码:


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stdio.h>
#define zz
using namespace std;
bool cmp(const string&s, const string&t){
        return s+t>t+s;
}
int main(){
#ifndef zz
        freopen("in.txt", "r", stdin);
#endif
        int n;
        while(scanf("%d", &n)!=EOF&&n){
                string s;
                int i, j;
                vector<string>vs;
                for(i=0; i<n; i++){
                        cin >> s;
                        vs.push_back(s);
                }
                sort(vs.begin(), vs.end(), cmp);
                for(i=0; i<vs.size(); i++)
                        cout << vs[i];
                cout << endl;
        }
        return 0;
}



目录
相关文章
|
5月前
|
Java
hdu 1257 最少拦截系统
hdu 1257 最少拦截系统
21 0
|
机器学习/深度学习 Java 算法
|
机器学习/深度学习