diff options
author | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-06-27 19:43:53 +0700 |
---|---|---|
committer | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-06-27 19:44:10 +0700 |
commit | 6f155876eee25e7db2b3080e0bf2a737d1201073 (patch) | |
tree | 85e0346e0485026fdd0ec6e9b965fd84e9970499 /12 | |
parent | 91b5248c8b951d82f3c9a2deb6ac928cce553497 (diff) | |
download | cp-6f155876eee25e7db2b3080e0bf2a737d1201073.tar.gz |
Clean up
Diffstat (limited to '12')
-rwxr-xr-x | 12/TP-HN-2008/R1/BL4.pas | 68 |
1 files changed, 52 insertions, 16 deletions
diff --git a/12/TP-HN-2008/R1/BL4.pas b/12/TP-HN-2008/R1/BL4.pas index 94dd3ba..c552b0d 100755 --- a/12/TP-HN-2008/R1/BL4.pas +++ b/12/TP-HN-2008/R1/BL4.pas @@ -1,26 +1,62 @@ var - f : text; - n : word; - a, b : array of longword; - tmp0, tmp1 : longword; + f: text; + n, i: int16; + a, b: array of int32; + + +procedure swp(var x, y: int32); + var + tmp: int32; -procedure ins(var l : array of longword; x : longword); begin - setlength(l, length(l) + 1); - l[length(l) - 1] := x + tmp := x; + x := y; + y := tmp end; + +procedure qsort(l, h: int16); + var + i, j: int16; + tmp: int32; + + begin + i := l; + j := h; + tmp := a[(l + h) div 2]; + + repeat + while a[i] < tmp do + inc(i); + while a[j] > tmp do + dec(j); + + if i <= j then + begin + swp(a[i], a[j]); + swp(b[i], b[j]); + inc(i); + dec(j) + end; + until i > j; + + if l < j then + qsort(l, j); + if i < h then + qsort(i, h) + end; + + begin - setlength(a, 0); - setlength(b, 0); assign(f, 'CLB.IN'); reset(f); readln(f, n); - for i := 1 to n do - begin - readln(f, tmp0, tmp1); - ins(a, tmp0); - ins(b, tmp1) - end; + setlength(a, n); + setlength(b, n); + for i := 0 to n - 1 do + readln(f, a[i], b[i]); close(f); - + qsort(0, n - 1); + for i := 0 to n - 1 do + writeln(a[i], ' ', b[i]) +end. |