Quick Schedule Exercises

Source: Internet
Author: User

Complete the Order of N (n<=100) personal age from small to large with a fast line, requiring the same monthly row for the year of birth.

Input: First line n personal

2 to N+1 Birth date (1992 9)

Output: The order of age from large to small.

Thought: Hey, originally was to examine the Double keyword sort, but we will not ... I wrote two quick rows.

 ProgramT1;type Age=RecordYear,mon:longint; End;varN,i,j:longint; A:Array[1.. -] ofAge ;proceduresort (l,r:longint);varI,j,x:longint; Y:age;beginI:=l; J:=R; X:=a[(L+r)Div 2].year; Repeat         whileA[i].year<x DoInc (I);  whileX<a[j].year DoDec (j); if  not(I&GT;J) Then        beginy:=A[i]; A[i]:=A[j]; A[J]:=y;            Inc (I); J:=j-1; End; untilI>J; ifL<j Thensort (l,j); ifI<r Thensort (i,r);End;procedureKP (l,r:longint);varI,j,x:longint; Y:age;beginI:=M; J:=R; X:=a[(L+r)Div 2].mon; Repeat         whileA[i].mon<x DoInc (I);  whileX<a[j].mon DoDec (j); if  not(I&GT;J) Then        beginy:=A[i]; A[i]:=A[j]; A[J]:=y;            Inc (I); J:=j-1; End; untilI>J; ifL<j ThenKP (L,J); ifI<r ThenKP (i,r);End;beginREADLN (n);  fori:=1  toN Doreadln (A[i].year,a[i].mon); Sort (1, N); J:=1;  fori:=1  toN Do    begin        ifa[i].year<>a[i+1].year Then        beginKP (j,i); J:=i+1; End; End;  fori:=1  toN DoWriteln (A[i].year,' ', A[i].mon);End.

Quick Schedule Exercises

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.