1 22 33 44 55 66 77 88 99 TenTen One One A A - - - - the the - - - - - - + + - - + + A A at at - - - -#include <iostream> -#include <algorithm> -#include <string> -#include <stdio.h> in#include <string.h> - using namespacestd; to BOOLcmpstringAstringb) + { - returna+b>b+A; the } * stringnum[ -]; $ intMain ()Panax Notoginseng { - intn,i; the while(cin>>n&&N) + { A for(i=0; i<n;i++) theCin>>Num[i]; +Sort (num,num+n,cmp); - for(i=0; i<n;i++) $cout<<Num[i]; $cout<<Endl; - } - return 0; the}
View Code
Sister West code, very good, string class does not need to consider other issues
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 #definefor (i,b,e) for (int i = b; I <= e; i++)6 #defineSC (x) scanf ("%d", &x)7 #defineSC1 (x) scanf ("%s", &x)8 using namespacestd;9 Const intINF = +, MAX = -;Ten structstr{ One CharS[inf]; A }num[max]; - CharStr1[inf], Str2[inf]; - intcmpConstStr A,ConstStr b) {//sort, connect 22 with AB or BA, if ab>ba, then put a in the back of B, and vice versa. the strcpy (str1, A.S); - strcat (str1, B.S); - strcpy (str2, B.S); - strcat (str2, A.S); + if(strcmp (str1, str2) >0) - return 1; + return 0; A } at intMainintargcChar*argv[]) { - intN, I; - while(SC (n), N) { -for (I,0, N-1) SC1 (NUM[I].S); -Sort (num, num+N, CMP); -for (I,0, N-1) inprintf"%s", NUM[I].S); -printf"\ n"); to } + return 0; -}
View Code
This code takes into account the struct, so that COM function is required
int cmp (const STR &a, const STR &b) {
strcpy (str1, A.S);
strcat (str1, B.S);
strcpy (str2, B.S);
strcat (str2, A.S);
if (strcmp (str1, str2) > 0)
return 1;
return 0;
}
UVA 10905 Children ' s Game