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