Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. Uses crt;
  2.  
  3.  
  4.  
  5.  
  6. type
  7.  
  8. elem = record
  9. data:string[25];
  10. next:^elem;
  11. end;
  12.  
  13.  
  14. var
  15. tail,buf,head: ^elem;
  16. n:integer;
  17. info:string[25];
  18. i:integer;
  19.  
  20.  
  21.  
  22.  
  23. procedure add(var head,tail:^elem;info:string[25]);
  24. begin
  25. if head = nil then
  26. begin
  27. new(head);
  28. head^.data:=info;
  29. head^.next:=nil;
  30. tail := head;
  31. //AddFirst(head,tail,info);
  32. end
  33. else
  34. begin
  35. new(tail^.next);
  36. tail:=tail^.next;
  37. tail^.next:=nil;
  38. end;
  39. tail^.data := info;
  40.  
  41. end;
  42.  
  43. procedure print(tail: ^elem);
  44. var i:^elem;
  45. begin
  46. i := tail;
  47. while i <> nil do
  48. begin
  49. writeln(i^.data);
  50. i:=i^.next;
  51. end;
  52.  
  53. writeln;
  54. end;
  55.  
  56. function getElemById(var head: ^elem;index:integer):^elem;
  57. var i:^elem;
  58. count:integer;
  59. begin
  60. i := head;
  61. count := 1;
  62. while (i <> nil) and (count < index) do
  63. begin
  64. i:=i^.next;
  65. inc(count);
  66. end;
  67.  
  68. Result := i;
  69.  
  70. end;
  71.  
  72.  
  73.  
  74. procedure sortirovka(var head,tail:^elem);
  75. var
  76. i,j,err,year1,k,year2,count:integer;
  77. sex,p : char;
  78. buf:string[25];
  79.  
  80. begin
  81. i:=1;
  82. while(i<=10) do
  83. begin
  84. //val(copy(mas[i],20,4),year,err);
  85. if(getElemById(head,i)^.data[24]='P') and (getElemById(head,i)^.data[25]='M') then
  86. //if (mas[i][24]='P') and (mas[i][25]='M') then
  87. begin
  88.  
  89. buf := getElemById(head,i)^.data;
  90. //buf := mas[i];
  91. for j:=i downto 2 do
  92. begin
  93.  
  94.  
  95.  
  96. getElemById(head,j)^.data := getElemById(head,j-1)^.data;
  97. //mas[j] := mas[j-1];
  98. end;
  99. //mas[1] := buf;
  100. getElemById(head,1)^.data := buf;
  101. inc(count);
  102.  
  103.  
  104. end;
  105.  
  106.  
  107. inc(i);
  108.  
  109. //writeln(year);
  110. end;
  111.  
  112.  
  113.  
  114.  
  115. for i:=1 to count-1 do
  116. begin
  117. for j:= i+1 to count do
  118. begin
  119. //getElemById(head,i)^.data
  120. val(copy(getElemById(head,i)^.data,20,4),year1,err);
  121. val(copy(getElemById(head,j)^.data,20,4),year2,err);
  122. //val(copy(mas[i],20,4),year1,err);
  123. //val(copy(mas[j],20,4),year2,err);
  124. if(year1 < year2) then
  125. begin
  126.  
  127. buf := getElemById(head,i)^.data;
  128. getElemById(head,i)^.data:= getElemById(head,j)^.data;
  129. getElemById(head,j)^.data := buf
  130. //buf := mas[i];
  131. //mas[i]:= mas[j];
  132. //mas[j] := buf;
  133. end;
  134. end;
  135.  
  136. end;
  137.  
  138. end;
  139.  
  140.  
  141. begin
  142. assign(input,'input.txt');
  143. reset(input);
  144. assign(output,'output_.txt');
  145. rewrite(output);
  146.  
  147. head := nil;
  148. tail := nil;
  149. for i:=1 to 10 do
  150. begin
  151. readln(input,info);
  152. writeln(output,info);
  153. add(head,tail,info);
  154. end;
  155. close(input);
  156. close(output);
  157.  
  158.  
  159. print(head);
  160.  
  161.  
  162. writeln(getElemById(head,2)^.data);
  163. sortirovka(head,tail);
  164.  
  165.  
  166.  
  167.  
  168. writeln;
  169.  
  170. print(head);
  171. (*
  172.  
  173. append(output);
  174.  
  175. writeln(output);
  176.  
  177. for i:=1 to 3 do
  178. begin
  179.  
  180. writeln(output,mas[i]);
  181. end;
  182. close(output);
  183.  
  184. writeln;
  185. for i:=1 to 3 do
  186. begin
  187.  
  188. writeln(mas[i]);
  189. end;
  190. *)
  191.  
  192. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement