Sword refers to the offer series source code-the array into the smallest number

Source: Internet
Author: User

Topic 1504: Nesting the array to the minimum time limit: 1 seconds memory limit: 128 trillion special sentence: No submission: 1463 resolution: 448 Title Description: Enter an array of positive integers, combine all the numbers in the array into a number, and print 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. Input: The input may contain multiple test samples. For each test case, the first behavior of the input, an integer m (1<=m <=100), represents the number of positive integers entered. The second line of input includes m positive integers, where each positive integer does not exceed 10000000. Output: corresponding to each test case, output the smallest number that the M number can be ranked. Sample input: 323 13 6223456 56 Sample output: 132362345656

#include <iostream> #include <stdio.h> #include <string> #include <cstring> #include < Algorithm>using namespace Std; int numbers[200];string str_num[200]; BOOL CMP (const string &STR1, const string &str2) {    string _str1 = str1;    string _str2 = str2;    _str1.append (STR2);    _str2.append (STR1);     return _STR1 < _STR2; } int main () {    int n;    while (scanf ("%d", &n)! = EOF) {        for (int i = 0; i < n; i + +)            scanf ("%d", numbers+i);         for (int i = 0; i < n; i + +) {            char str[20];            sprintf (str, "%d", numbers[i]);            Str_num[i] = str;        }         Sort (str_num, str_num+n, CMP);         for (int i = 0; i < n; i + +) {            cout << str_num[i];        }        cout << Endl;    }    return 0;}

Sword refers to the offer series source code-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.