The configuration of vim today is not successful, always show what error, alas, in fact, before the success of the only re-installed Dev, and then changed, perhaps the environment
Variable problem, but I have changed, ah, later adjust it ...
This problem is actually not I think out of the puzzle, and look at the question ... Well, now that you've seen the puzzle, you have to master it. I've just been using it.
C + + Primer inside Learn the string class, very useful, I am ready to write the program as far as possible with C + + content, more practice.
It also deepens the understanding of the CMP function called by Qsort, whose two parameters are actually pointers to the elements to be compared, such as the element in this question is the string class
Type, then they are all string types of pointers ... The comparison is OK, the return value is 1 is the ascending order, 1 is descending order ...
In fact, the qsort of Baidu Encyclopedia is very detailed, you can refer to the reference.
Solution:
In fact, in the sort of time a little more changes, the a+b and b+a the larger values to the front can be, + in the string class can be a string connection,
With a two-dimensional character array can also, see a person wrote in the CMP function added a few characters copy function, and then compare, in fact, the comparison of A+b and b+a ...
Code:
#include <stdio.h> #include <iostream> #include <stdlib.h> #include <string.h> #include < String>using namespace std;string str[55];int cmp (const void *a,const void *b) {return * (String *) a +* (String *) b < * (String *) B + * (String *) A;} int main () {int i,n;while (CIN >> N, N) {for (i=0; i<n; i++) cin >> Str[i];qsort (str,n,sizeof (str[0]), CMP); for (i=0; i<n; i++) cout << str[i];cout << Endl;} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVA 10905 Children ' s Game (sort or a bit greedy)