注意:最小数为0时,要输出“0”

AC代码

#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
bool cmp(const string& a,const string& b){
    string reta,retb;
    reta = a + b;
    retb = b + a;
    if(reta < retb)
        return true;
    else
        return false;
}
int main(){
    int n;
    vector<string> v;
    scanf("%d",&n);
    for(int i = 0;i < n;i++){
        string tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(),v.end(),cmp);
    bool first(true);
    for(int i = 0;i < v.size();i++){
        for(int j = 0;j < v[i].size();j++){
            if(first && v[i][j] != '0' || !first){
                printf("%c",v[i][j]);
                first = false;
            } 
        }
    }
    if(first)
        printf("0\n");
    return 0;
}

 

posted on 2016-03-02 12:42  aldorado  阅读(114)  评论(0编辑  收藏  举报