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