剑指offer 面试题33 数组组合的最小数
2014-12-27 15:04
543 查看
#include <stdio.h> #include <stdlib.h> #include <cstring> //#include <algorithm> int compare(const void *num1,const void *num2){ char comb1[21],comb2[21]; strcpy(comb1,*(const char**)num1); strcat(comb1,*(const char**)num2); strcpy(comb2,*(const char**)num2); strcat(comb2,*(const char**)num1); return strcmp(comb1,comb2); } void MinNum(int *num,int len){ if(!num || len<=0) return; //char **pNum=(char**)(new int [len]); char **pNum=new char *[len]; for(int i=0;i<len;++i){ pNum[i]=new char[11]; sprintf(pNum[i],"%d",num[i]); } qsort(pNum,len,sizeof(char*),compare); for(int i=0;i<len;++i) printf("%s",pNum[i]); printf("\n"); for(int i=0;i<len;++i){ delete []pNum[i]; } delete pNum; } int main(){ int num[]={3,32,321}; MinNum(num,sizeof(num)/sizeof(*num)); }
相关文章推荐
- 剑指Offer面试题33(java版):把数组排成最小的数
- 【剑指Offer学习】【面试题33:把数组排成最小的数】
- 【剑指offer】5.2时间效率——面试题33:把数组排成最小的数
- 【剑指offer】面试题33-把数组排成最小的数
- 剑指Offer——面试题33:把数组排成最小的数
- 剑指offer-面试题33:把数组排成最小的数
- 剑指Offer之面试题33:把数组排成最小的数
- 剑指Offer:面试题33 把数组排成最小的数
- 剑指offer面试题33:把数组排成最小的数
- 剑指offer--面试题33:把数组排成最小的数
- 【剑指Offer】面试题33:把数组排成最小的数
- 剑指offer 面试题33—把数组排成最小的数
- 剑指Offer----面试题33:把数组排成最小的数
- 剑指offer-面试题33-把数组排成最小的数
- 【剑指Offer学习】【面试题33:把数组排成最小的数】
- 剑指Offer面试题33把数组排成最小的数,面试题34丑数
- 剑指offer面试题8:旋转数组的最小数字
- 剑指offer面试题 旋转数组的最小数字
- 剑指 offer——面试题8求旋转数组的最小值
- 旋转数组的最小数字(剑指offer面试题)