1038 Recover the Smallest Number
思路:
直接按位排序,对不同长度的字符串分情况讨论(从没写过这么长的cmp函数)
坑:
测试点2 全部都是0;
因为输出最终数字的时候开头的0不输出,所以设立一个标志位检测省略过开头的0没,什么都没输出(全部省略)就再补充一个0
AC代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct number{
char num[10];
int len;
int index;
}a[10010];
bool cmp(number a,number b){
if(a.num[0]!=b.num[0]) return a.num[0]<b.num[0];
else{
for(int i=0;i<min(a.len,b.len);i++){
if(a.num[i]!=b.num[i]){
return a.num[i]<b.num[i];
}
}
if(a.len<b.len){
if(b.num[a.len]!=a.num[0]) return a.num[0]<b.num[a.len];
els