Using the system's own fast-line function in C language

Source: Internet
Author: User
Tags ticket

Topic

1015. The Moral Only theory ( -)The Song Dynasty historian Sima Guang in "the Capital Governance Tong Jian" has a famous "The Moral Only Theory": "is therefore only then the virtuous all says the sage, only then the German and the death is the Fool, the German wins only then is said the gentleman, only then wins the moral to be the villain. Whoever takes the technique of the person, Gou not saints, gentleman and with it, with the villain, not if the fool. "Now give a number of candidates of the German score, please according to Sima Guang theory to give admission rankings." Input format: Enter the 1th line to give 3 positive integers, respectively: N (<= the), that is, the total number of candidates; L (>= -), for the admission of the minimum score, that is, the German and want $ are not less than L candidates are eligible to be considered for admission; H (< -), for the priority admission line-the German and want $ are not below this line is defined as "only de full", such candidates by virtue of the total score from high to low sort; want $, but the German division to the line of a class of candidates belonging to the "De Sheng", but also ranked in the first category, the German want $ are lower than H, But the score of not less than want $ candidates belong to "only Germany and death" but there are "De Sheng only", according to the total ranking, but ranked after the second category of candidates; other candidates who reached the minimum line L were ranked by total, but ranked after the third category of candidates. Then n lines, each line gives a candidate's information, including: The ticket number, German points, want $, where the ticket number is a 8-bit integer, Germany is divided into intervals [0, -] within the integer. The numbers are separated by a space. Output format: Output line 1th first give the number of candidates to achieve the minimum fraction m, followed by M line, each line according to the input format to output a candidate's information, candidates according to the rules indicated in the input from high to low sort. When a certain number of candidates in the same time, according to their German points in descending order; If the German points are also tied, the ticket number in the ascending output. Input Sample: -  -  the10000001  -  -10000002  -  -10000011  -  the10000003  -  the10000004  the  -10000005  the  the10000006  the  the10000007  -  +10000008  the  -10000009  -  -10000010  the  $10000012  the  -10000013  -  About10000014  the  -Sample output: A10000013  -  About10000012  the  -10000003  -  the10000011  -  the10000004  the  -10000007  -  +10000006  the  the10000005  the  the10000002  -  -10000014  the  -10000008  the  -10000001  -  -

With the use of multi-field sorting, it is most appropriate to call the system's own fast ordering, and to implement its own CMP function.

#include <stdio.h>#include<stdlib.h>#include<malloc.h>typedefstruct{    intnum; intD; intC;} Student;intCompConst void*a,Const void*b) {
Sort by total score minusif((* (* (student*) a). d+ (* (student*) a). c! = (* (student*) b). d+ (* (student*) (b). c)return((* (student*) b). d+ (* (student*) b). C)-(((* (* (student*) a). d+ (* (student*) (a). c);
Sort by moral DivisionElse if((* (* (student*) a). D! = (* (student*) (b). D)return(* (student*) b). D (* (student*) a). D;
Follow the learning increment sortElse return(* (student*) a). num-(* (student*b). Num;}intMain () {intN,l,h,i,count=0; intNum,d,c; intn1=0, n2=0, n3=0, n4=0; Student*P1; Student*P2; Student*P3; Student*P4; Student temp; scanf (" %d%d%d",&n,&l,&h); P1= (Student *)malloc(100000*sizeof(student)); P2= (Student *)malloc(100000*sizeof(student)); P3= (Student *)malloc(100000*sizeof(student)); P4= (Student *)malloc(100000*sizeof(student)); for(i=0; i<n;i++) {scanf (" %d%d%d",&temp.num,&temp.d,&temp.c); if((temp.d>=l) && (temp.c>=l)) {if((temp.d>=h) && (temp.c>=h)) P1[n1++] =temp; Else if(temp.d>=h) p2[n2++] =temp; Else if(temp.d>=temp.c) P3[n3++] =temp; Elsep4[n4++] =temp; }} qsort (P1,n1,sizeof(student), comp); Qsort (P2,N2,sizeof(student), comp); Qsort (P3,n3,sizeof(student), comp); Qsort (P4,n4,sizeof(student), comp); printf ("%d\n", n1+n2+n3+N4); for(i=0; i<n1;i++) printf ("%d%d%d\n", P1[I].NUM,P1[I].D,P1[I].C); for(i=0; i<n2;i++) printf ("%d%d%d\n", P2[I].NUM,P2[I].D,P2[I].C); for(i=0; i<n3;i++) printf ("%d%d%d\n", P3[I].NUM,P3[I].D,P3[I].C); for(i=0; i<n4;i++) printf ("%d%d%d\n", P4[I].NUM,P4[I].D,P4[I].C); return 0;}

Using the system's own fast-line function in C language

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.