fork download
  1. program SortingLaba5;
  2.  
  3. type
  4. index=byte;
  5. item=word;
  6. const
  7. n=8;
  8. var
  9. i,j,m,l,r,k :index;
  10. x,max,max1 :item;
  11. a :array[1..n,1..n] of item;
  12.  
  13.  
  14. begin
  15. { TODO -oUser -cConsole Main : Insert code here }
  16.  
  17. randomize;
  18. for i:=1 to n do
  19. begin
  20. for j:=1 to n do
  21. begin
  22. a[i,j]:=random(1000);
  23. write(a[i,j]:5)
  24. end;
  25. writeln
  26. end;
  27.  
  28. {----------------------------------------------}
  29.  
  30. for i:=2 to n do
  31. begin
  32. max:=a[i,1];
  33. for j:=2 to n do
  34. if a[i,j]>max then
  35. max:=a[i,j];
  36. l:=1;
  37. r:=i;
  38. while l<r do
  39. begin
  40. m:=(l+r) div 2;
  41. max1:=a[m,1];
  42. for j:=2 to n do
  43. if a[m,j]>max1 then
  44. max1:=a[m,j];
  45. if max1<=max then
  46. l:=m+1
  47. else
  48. r:=m
  49. end;
  50.  
  51. for k:=1 to n do
  52. begin
  53. x:=a[i,k];
  54. for j:=i downto r+1 do
  55. a[j,k]:=a[j-1,k];
  56. a[r,k]:=x
  57. end
  58. end;
  59.  
  60. {----------------------------------------------}
  61. writeln;
  62. writeln;
  63.  
  64. for i:=1 to n do
  65. begin
  66. for j:=1 to n do
  67. write(a[i,j]:5);
  68. writeln
  69. end;
  70. readln;
  71.  
  72. end.
  73.  
Success #stdin #stdout 0.01s 5284KB
stdin
8908
loj
stdout
  545  265  505  186   85  782   78  311
  614  170  536  136  976  973  381  303
  669  285  447  845  114  606  317  625
  971  741  514  650   32  673  141  650
  933  200  253  330  523  328  465  362
  646  314  581  886   22  931  460  464
   79   65  177  490  578  941  725  376
  842   33  206  633  156  672  802  514


  545  265  505  186   85  782   78  311
  842   33  206  633  156  672  802  514
  669  285  447  845  114  606  317  625
  646  314  581  886   22  931  460  464
  933  200  253  330  523  328  465  362
   79   65  177  490  578  941  725  376
  971  741  514  650   32  673  141  650
  614  170  536  136  976  973  381  303