The sword offer-the array into the smallest number.

Source: Internet
Author: User

The sword offer-the array into the smallest number.

The title description enters an array of positive integers, stitching up all the numbers in the array into a number, and printing the smallest of all the numbers that can be stitched together. For example, enter the array {3,32,321}, then print out the minimum number that these three numbers can be ranked as 321323.

Exercises

Use the CMP function of the sort function to arrange the smallest to largest number of combinations

BOOL Cmp (int a, int b) {    int a_num = 0, B_num = 0, at = a, bt = b;    while (at) {        a_num++;         at/=;     }    while (BT) {        b_num++;         BT/=;     }    at = B*pow (ten, a_num) + A;     BT = A*pow (Ten, b_num) + B;     Return BT < at; }class Solution {public:    string printminnumber (vector<int> numbers) {        sort (numbers.begin (), Numbers.end (), Cmp);         String ans = "";         for (int i=0; i<numbers.size (); ++i) {            ans + to_string (numbers[i]);         }        return ans;     };

  

The sword offer-the array into the smallest number.

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.