Title: Http://acm.hust.edu.cn/vjudge/contest/view.action?cid=68990#problem/A
Topic Requirements:, give n numbers, reorder them to get a maximum number, as if given 123 456 789 to spell 789456123 Max
This problem can be regarded as a sort of problem, but the rules of the sort are fastidious
If you want to sort by dictionary order, obviously wrong, like 999123 999, sorted by dictionary order 999123 in front, get the number 999123999, obviously not enough 999999123 big
Problem analysis: Bubble sort, first sorted by dictionary order, so that the number of exchange of bubble sort can be greatly reduced.
If there are two numbers 90 9, if sorted by dictionary order then 90>9, at this time compare strcat ("90", "9") with ("9", "90") size, make large with small position exchange. Please look at the code for specific actions, you will understand what the meaning of.
#include <iostream>#include<string.h>#include<stdio.h>#include<algorithm>#include<math.h>#include<queue>#defineEPS 1e-9typedefLong Longll;using namespacestd;intN;Charstr[101];Chara[ -][101];Chars2[202],s3[202];intcmpConst void*a,Const void*b) { returnstrcmp ((Char*) B, (Char*) a);}intMain () { while(SCANF ("%d", &n)!=eof&&n!=0) { for(intI=0; i<n;i++) scanf ("%s", A[i]); Qsort (A,n,sizeof(a[0]), CMP); for(intI=1; i<n;i++) { for(intj=0; j<n-i;j++) {strcpy (s2,a[j+1]); strcat (S2,a[j]); strcpy (S3,a[j]); strcat (S3,a[j+1]); if(strcmp (S2,S3) >0) {strcpy (str,a[j]); strcpy (A[j],a[j+1]); strcpy (A[j+1],str); //printf ("%s%s\n", a[j],a[j+1]); } } } for(intI=0; i<n;i++) {printf ("%s", A[i]); } cout<<Endl; } return 0;}
Uva10905:children ' s Game (sort)