With n positive integers (n <= 20), connect them into a row, form a maximum number of multiple digits

xiaoxiao2021-03-06  54

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 #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 #include #include #include usespace std;

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 () S2;}}}}}}} = S2.SIZE ()) {RETURN S1> S2;}}}}; int main ()}}}; int main () {// results: 7 4 423 1 // Char * PS [] = {"7", "42", " 3 "," 4 "," 1 "}; // RESULT: 4 432 42 3 1 // Char * ps [] = {" 432 "," 4 "," 42 "," 3 "," 1 "} ; // RESULT: 71 711 7112 4 432 42 3 1 // CHAR * PS [] = {"7112", "71", "711", "4", "432", "42", "3", "1"}; //7 77 7771 7118 711 // char * ps [] = {"7771", "7", "77", "7118", "711"}; //717 7171712 71 // char * ps [] = {"71", "717", "717712"}; // 7118 7117 711 char * ps [] = {"7118", "711", "7117"}; Vector V (ps, ps sizeof (ps) / sizeof (* ps)); sort (v.begin (), v.end (), comp ()); copy (v.begin (), v.end ), ostream_iterator (cout, ")); cout << endl;}

WHYGLINUX code 2: #include #include #include #include #include using namespace std; Bool Compare (Const String & S1, Const String & S2) {IF (S1.SIZE () == 0) Return False; if (S2.SIZE () == 0) Return True; Int min_siz = s1.size () S2;}} int Main () {// Result: 7 4 42 3 1 // char * ps [] = {"7", "42", "3", "4", "1"}; // RESULT: 4 432 42 3 1 // Char * ps [] = {"432", "4" , "42", "3", "1"}; // Result: 71 711 7112 4 432 42 3 1 // Char * ps [] = {"7112", "71", "711", "4" , "432", "42", "3", "1"}; //777 7771 7118 711 OR 77 77771 7118 711 Char * ps [= {"7771", "7", "77", "7118", "711"}; // 717 7171712 71 // char * ps [] = {"71", "717", "717712"} // 7118 7117 711 // char * ps [] = {"7118", "711", "7117"}; vector V (ps, ps sizeof (ps) / sizeof (* ps)); sort (v.egin (), v.end (), compare; copy (v.begin (), v.end (), ostream_iterator (cout, ")); cout << endl;}

Squall1009 (learning ING) code: include #include using namespace std; int weiShu (int M); int Fun1 (int M, int N); int main () {const INT N = 20; INT B, N, I, J, BIG; INT A [n] = {0}; cout << "Please enter the number of positive integers you want to enter:"; cin >> n; for (i = 0; i > a [i];} for (i = 0; i

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 V (ps, ps SIZEOF (PS) / SizeOf (* ps)); sort (v.begin (), v.end (), compare); copy (v.begin (), v.end (), ostream_iterator (cout , "")); Cout << Endl; System ("pause"); return 0;}

IICUP (Double Cup Wine) code: // Now proposes an efficient algorithm // only looks to the length of some // vc 6.0 # include #include #include usingspace std; // If S1 should return TRUE before S2, otherwise returns falsebool compare (const char * s1, const char * s2) {if (S1 == 0) Return false; if (S2 == 0) return true; const char * temps1 = S1; const char * TEMPS2 = S2; While ((* temps1 == 0) && (* temps2 == 0))) {// string added effect if (* temps1 == 0) {TEMPS1 = S2;} if (* temps2 == 0) {TEMPS2 = S1;} // Compare IF (* Temps1! = * TEMPS2) {RETURN * TEMPS1> * TEMPS2;} else {temps1 ; temps2 ;}

} // Two equal returnography;}

Int main () {

// Test data char * ps [] = {"35335", "35335353", "53553", "53553535"}; // correct result 53553535 53553 35335 35335353

Vector v (ps, ps sizeof (ps) / sizeof (* ps)); sort (v.begin (), v.end (), compare); copy (v.begin (), v. End (), ostream_iterator (cout, "))); cout << end1; return 0;} // output: // 53553535 53553 35335 35335353

/ / Now propose a digital-based algorithm // VC 6.0 # include #include #include using namespace std;

/ / 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 V (Data, Data Sizeof (data) / sizeof (Data [0]) ); Sort (v.begin (), v.end (), compare; copy (v.begin (), v.end (), ostream_iterator (cout, ")); cout << Endl Return 0;} // output: //53553535 53553 35335 35335353

转载请注明原文地址:https://www.9cbs.com/read-114888.html

New Post(0)