zoukankan      html  css  js  c++  java
  • pat 1038 Recover the Smallest Number

    大一上玩熟练的linux现在又是一团浆糊,从头学命令行花了我一个小时QAQ

    wen ti bu da

    bu,hen da

    anyway~
    这个题一开始可能在想某种规律234 23 //534 53 的排序就不一样

    但实际上这个题是想麻烦了...其实只需要一个排序就ok了,而排序的方法就也很明显,就a+b >b+a就好了

    这个题有一个注意点就是前导零,如 00 000 000这种,直接输出0 (这块需要判断)

    
    #include <algorithm>
    #include<iostream>
    #include<stdio.h>
    #include<string>
    using namespace std;
    bool cmp(string a,string b){
        return a+b<b+a;
    }
    int main(){
        int n;
        string str[10020];
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            cin>>str[i];
        }
        sort(str,str+n,cmp);
        string ans="";
        for(int i=0;i<n;i++){
            ans+=str[i];
        }
        while(ans[0]=='0'&&ans.size()!=0){
            ans.erase(ans.begin());
        }
        if(ans.size()==0)
            cout<<0;
        else{
            cout<<ans;
        }
        return 0;
    
    }
    
    
    为了自己,和那些爱你的人
  • 相关阅读:
    js-AOP
    jQueryUI之autocomplete
    nginx安装配置
    oracle结构语法
    ajax/表单提交 多个相同name的处理方法
    ES6模块化
    docker运维
    帆软报表
    oracle锁表
    香港到大陆IPLC节点故障
  • 原文地址:https://www.cnblogs.com/zhmlzhml/p/15047457.html
Copyright © 2011-2022 走看看