Solve with C + +: Arrange the array into the smallest number problem

Source: Internet
Author: User

Problem Description:
Enter an array of positive integers, combine all the numbers in the array into a number, and print out the smallest of all the numbers that are stitched together. For example, the input array {3,32,321} prints out the smallest number 321323 that these 3 numbers can be taken.
C + + code:

voidPrintminnumber (int* Numbers,intLength) {if(numbers = = NULL | | length <=0)return;StringStreamss//used for numeric and string conversions;    string* str=New string[Length]; for(inti =0; i < length;        ++i) {ss.clear ();        ss<<numbers[i];     ss>>str[i]; } sort (str,str+length, compare); for(inti =0; i < length; ++i)cout<< Str[i];printf("\ n");}BOOLCompareConst stringStrNumber1,Const stringStrNumber2) {stringSTR1 = Strnumber1+strnumber2;stringSTR2 = Strnumber2+strnumber1;returnSTR2&GT;STR1;}

Solve with C + +: Arrange the array into the smallest number problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.