9-degree OJ Document Sorting

Source: Internet
Author: User
Tags strcmp
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'

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.


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 ).


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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.