Cause: nine degrees some questions are online test questions, no discussion area, this Samsung question I think the AC rate is quite low, so I posted my own AC Code For everyone to learn and discuss the research point: the research point is used in the structure, and an array is used for copying. At the same time, note that the string Terminator is '\ 0'
-
Description:
-
Now, your tutor gives you a list of references to be sorted. You need to sort them in order.
Each document record in the document list occupies only one row. The sorting rules are the same as those for string-type strings (if the string contains uppercase letters during sorting, it is processed as lowercase letters to ensure that there are no strings of the same size, but the output results cannot change any string), in ascending order.
-
Input:
-
The input includes multiple groups. The first line of each group includes an integer N, (1 <= n <= 200), and then there are n rows. Each row includes one line of Document Records, length of document record S (1 <=s <= 200 ).
-
Output:
-
Input to each group. Output sorted documents.
-
Sample input:
-
3abc hello!
ABC Hellz!
BBC hello!
-
Sample output:
-
ABC hello!
ABC Hellz!
BBC hello!
AC code:
# Include <stdio. h> # include <stdlib. h> # include <ctype. h> # include <string. h> struct literature {char str1 [201]; char str2 [201] ;}; int partition (struct literature * a, int left, int right ); void quicksort (struct literature * a, int begin, int end); int main () {int N, I, j; struct literature docus [201]; char ch; while (scanf ("% d", & N )! = EOF) {// absorb carriage return CH = getchar (); // receive document data for (I = 0; I <n; I ++) {gets (docus [I]. str1) ;}// assign a value to the array (I = 0; I <n; I ++) {for (j = 0; docus [I]. str1 [J]! = '\ 0'; j ++) {If (isalpha (docus [I]. str1 [J]) {docus [I]. str2 [J] = tolower (docus [I]. str1 [J]);} else {docus [I]. str2 [J] = docus [I]. str1 [J] ;}} docus [I]. str2 [J] = '\ 0';} // quick sorting quicksort (docus, 0, n-1); // print the output for (I = 0; I <N; I ++) {printf ("% s \ n", docus [I]. str1) ;}} return 0;} void quicksort (struct literature * a, int begin, int end) {int begin; If (begin <End) {begin = partition (, begin, end); quicksort (A, begin, begin-1); quicksort (A, begin + 1, end) ;}} int partition (struct literature * a, int left, int right) {struct literature stand = A [left]; while (left <right) {While (left <Right & strcmp (A [right]. str2, stand. str2)> = 0) {right --;} If (left <right) {A [left ++] = A [right];} while (left <Right & strcmp (A [left]. str2, stand. str2) <= 0) {left ++;} If (left <right) {A [Right --] = A [left] ;}} A [left] = stand; return left ;}