With n positive integers (n <= 20), connect them into a row, form a maximum number of multiple digits. For example, when n = 3, the maximum integersion between 3 integers 13, 312, 343 is: 34331213, such as: n = 4, the maximum integer of 4 integer 7, 13, 4, 246 is 7424613 program input : N Program Output: N numbers of N numbers are connected. This question is a job that the teacher stayed. After I sent it to 9CBS, I didn't expect the discussion. There are some netizens' code below. http://community.9cbs.net/expert/topic/3372/3372952.xml?temp=.9760858
LUJianping (Lujianping) code: #include
#define min (x, y) ((x)> (y): (x))
INT newstrcmp (char * psznum1, char * psznum2) {IF (strlen (psznum1) == 0) RETURN-1; IF (strlen (psznum2) == 0) Return 1;
Unsigned int nminlen = min (strlen (psznum1), strlen (psznum2)); int NRESULT; // If a string is prefixed with another string IF ((NRESULT = STRNCMP (psznum1, psznum2, nminlen) == 0 ) {If (nminlen == Strlen) {Return NewStrCMP (PSZNUM1, PSZNUM2 NMINLEN);} else {return newstrcmp (psznum1 nminlen, psznum2);}} else {// If not, return comparison Result RETURN NRESULT;
Return 0;} int Main (int Argc, char * argv []) {// recult: 7 4 423 1 s // char * psznum [] = {"7", "42", "3", "4 "," 1 "}; // RESULT: 4 432 42 3 1 // Char * psznum [] = {" 432 "," 4 "," 42 "," 3 "," 1 "}; // result: 71 711 7112 4 432 42 3 1 CHAR * PSZNUM [] = {"7771", "7", "77", "7118", "711"};
// Use bubbling sort for (unsigned int i = 0; i WHYGLINUX code 1: #include Struct Comp {BOOL Operator () (String S1, String S2) {string :: size_type pos; while (1) {if (s1.size ()> s2.size ()) {for (POS = 0; s1.find (S2, POS) == POS; POS = S2.SIZE ()); S1.RASE (0, POS); if (S1.SIZE () == 0 || S1.Size ()> s2.size () ) {RETURN S1> S2;}} f (s1.size () WHYGLINUX code 2: #include Squall1009 (learning ING) code: include INT FUN1 (INT M, INT N) {Int A, B; A = Weishu (M); B = Weishu (N); IF ((M * Pow (10.0, B) N)> (N * Pow (10.0 , a) m)) RETURN 1; else returnography;} CPUNION (INT ARGC, CHAR ** Argv) code: #define min (x, y) (x Bool Compare (Const String & S1, Const String & S2) {int RET = STRNCMP (S1.C_STR (), S2.C_STR (), Min (S1.Length (), S2.LENGTH ())); if (Ret == 0) RETURN S1 S2> S2 S1; ELSE RETURN RET> 0;} INT main () {// Test data char * ps [] = {"35335", "53553", "53553535"}; // correct result 53553535 53553 3535 35335353 Vector IICUP (Double Cup Wine) code: // Now proposes an efficient algorithm // only looks to the length of some // vc 6.0 # include } // Two equal returnography;} Int main () { // Test data char * ps [] = {"35335", "35335353", "53553", "53553535"}; // correct result 53553535 53553 35335 35335353 Vector / / Now propose a digital-based algorithm // VC 6.0 # include / / If D1 should return True before D2, otherwise returns FalseBool Compare (unsigned int D1, unsigned int d2) {if (d1 == 0) Return False; if (d2 == 0) return true; unsigned __int64 tempd1_1 = d1; unsigned __int64 tempd1_2 = d1; unsigned __int64 tempd2_1 = d2; unsigned __int64 tempd2_2 = d2; while (tempd2_2) {tempd1_1 * = 10; tempd2_2 / = 10;} while (tempd1_2) {tempd2_1 * = 10; tempd1_2 / = 10 } RETURN TEMPD1_1 D2> Tempd2_1 D1;} Int main () { // Test data unsigned int data [] = {35335, 353353535}; // correct result 53553535 53553 35335 3533535353 35335 35335353VECTOR