1038 recover the smallest number

注意:最小数为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
");
    return 0;
}
原文地址:https://www.cnblogs.com/Aldorado/p/5234473.html