//
// main.cpp
// PAT_1038. Recover the Smallest Number
//
// Created by wjq on 17/5/7.
// Copyright © 2017年 wjq. All rights reserved.
//
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
string number[10005];
int N,c=0;
string firstNumber;
int cmp(string a,string b)
{
return a+b<b+a;
}
int main(int argc, const char * argv[])
{
cin>>N;
for(int i=0;i<N;i++)
cin>>number[i];
sort(number,number+N,cmp);
bool output=false;
for(int i=0;i<N;i++)
if(atoi(number[i].c_str())==0)
continue;
else if(c==0)
{
output=true;
cout<<atoi(number[i].c_str());
c++;
}
else
cout<<number[i];
if(output==false)
cout<<0;
return 0;
}
一开始没想到好的思路,自己写的排序........Orz,当只有冒泡排序的效率,最后一个点超时了.....看了网上的博客,sort还能这么玩的!!学到了.,
之后第三个点一直是错误,后来发现输入数据全是0的时候,我的程序没有任何输出.讲道理应该是要输出一个0的.所以打了个很丑的补丁- -.