S.PAS 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. uses CRT;
  2. type
  3. plist=^list;
  4. list=record
  5. b:real;
  6. next:plist;
  7. end;
  8. plist3=^list3;
  9. list3=record
  10. b:char;
  11. next:plist3;
  12. end;
  13. {----------------------------------}
  14. function p1(l:plist; e:list):boolean;
  15. begin
  16. if l=nil then
  17. p1:=false
  18. else
  19. begin
  20. if l^.b = e.b then
  21. p1:=true
  22. else
  23. p1:=p1(l^.next, e);
  24. end;
  25. end;{p1}
  26. {----------------------------------}
  27. procedure p2(l:plist;e:list;var num:byte);
  28. begin
  29. if l<>nil then
  30. begin
  31. if l^.b=e.b then
  32. inc(num);
  33. p2(l^.next,e,num);
  34. end;
  35. end;{p2}
  36. {----------------------------------}
  37. function p11(l:plist):boolean;
  38. {var num:byte; }
  39. begin
  40. if l<>nil then
  41. begin
  42. if l^.b=l^.next ^.b then p11:=true;
  43. exit
  44. end
  45. else
  46. p11:=p11(l^.next)
  47. else
  48. p11:=false
  49. end;
  50. end;{p11}
  51. {----------------------------------}
  52. procedure p3(l:plist;var MAX:real);
  53. begin
  54. if l <>nil then
  55. begin
  56. if l^.b > max then max:=l^.b ;
  57. p3(l^.next,max);
  58. end;
  59. end;{p3}
  60. {----------------------------------}
  61. procedure p4(l:plist3);
  62. begin
  63. if l<>nil then
  64. begin
  65. p4(l^.next);
  66. write(l^.b);
  67. end;
  68. end;{p4}
  69. {----------------------------------}
  70. procedure p5(l:plist;e1,e2:list);
  71. begin
  72. if l<>nil then
  73. begin
  74. if l^.b=e1.b then
  75. l^.b:=e2.b;
  76. p5(l^.next,e1,e2);
  77. end;
  78. end;{p5}
  79. {----------------------------------}
  80. procedure p6(l:plist;e:list);
  81. var
  82. lishniy:plist;
  83. begin
  84. if l^.next<>nil then
  85. begin
  86. if l^.next^.b=e.b then
  87. begin
  88. lishniy:=l^.next;
  89. l^.next:=l^.next^.next;
  90. dispose(lishniy);
  91. end
  92. else
  93. p6(l^.next,e)
  94. end;
  95. end;{p6}
  96. {----------------------------------}
  97. procedure p7(l:plist;e:list);
  98. var
  99. lishniy:plist;
  100. begin
  101. if l^.next<>nil then
  102. begin
  103. if l^.next^.b=e.b then
  104. begin
  105. lishniy:=l^.next;
  106. l^.next:=l^.next^.next;
  107. dispose(lishniy);
  108. end;
  109. p7(l^.next,e)
  110. end;
  111. end;{p7}
  112. {----------------------------------}
  113. function p8(l:plist):plist;
  114. var
  115. n:plist;
  116. begin
  117. if l <> nil then
  118. begin
  119. new(n);
  120. n^.b:=l^.b;
  121. n^.next := p8(l^.next);
  122. end;
  123. p8:=n;
  124. end;{p8}
  125. {----------------------------------}
  126. procedure p9(l:plist;e:list);
  127. var
  128. n:plist;
  129. begin
  130. if l<>nil then
  131. begin
  132. if l^.b=e.b then
  133. begin
  134. new(n);
  135. n^.b:=e.b;
  136. n^.next:=l^.next;
  137. l^.next:=n;
  138. p9(l^.next^.next,e);
  139. end
  140. else
  141. p9(l^.next,e);
  142. end;
  143. end;{p9}
  144. {----------------------------------}
  145. function p10(l:plist;sum:real;num:word):real;
  146. begin
  147. if l<>nil then
  148. p10:=p10(l^.next,sum+l^.b,num+1)
  149. else
  150. p10:=sum/(num-1);
  151. end;
  152. {----------------------------------}
  153. function NewList:plist;
  154. var
  155. NN,p : plist;
  156. i: byte;
  157. begin
  158. nn:=nil;p:=nil;
  159. for i := 1 to 10 do
  160. begin
  161. New(p);
  162. Read(p^.b);
  163. P^.next:=nn;
  164. nn:=p;
  165. end;
  166. Newlist:=NN;
  167. end; {NewList}
  168. {--------------}
  169. function NewList2:plist3;
  170. var
  171. NN,p : plist3;
  172. i: byte;
  173. begin
  174. nn:=nil;p:=nil;
  175. for i := 1 to 10 do
  176. begin
  177. New(p);
  178. Read(p^.b);
  179. P^.next:=nn;
  180. nn:=p;
  181. end;
  182. Newlist2:=NN;
  183. end; {NewList}
  184. {--------------}
  185. Procedure WriteList(L:plist);
  186. var p : plist;
  187. begin
  188. p:=l;
  189. while p <> nil do
  190. begin
  191. Write(p^.b:0:2,' ');
  192. p:=p^.next;
  193. end;
  194. end;{WriteList}
  195. var
  196. l1,LL : plist;
  197. l2 : plist3;
  198. e,e2 : list;
  199. k : byte;
  200. m : real;
  201. begin
  202. L1:=nil;ll:=nil;
  203. WriteLN('Введите 10 чисел');
  204. LL:=NewList;
  205. Write('Введите зн-е e');
  206. Read(e.b);
  207. if p1(LL,e) then
  208. begin
  209. k:=0;
  210. p2(LL,e,k);
  211. WriteLn('Найдено!, ',k,' раз');
  212. end
  213. else WriteLn('Не найдено!');
  214. m := LL^.b;
  215. {-------------------------------------}
  216. p11(ll) ;
  217. writeln(p11(ll))
  218. ;
  219. p3(LL,m);
  220. WriteLn('Максимум: ',m:0:2);
  221. WriteLn('Введите 10 символов (по очереди!)');
  222. l2:=NewlIst2;
  223. Write('А теперь обратно: ');
  224. p4(l2);
  225. writeln;
  226. WriteLn('Список до:');
  227. WriteList(LL);
  228. writeln;
  229. WriteLn('Введите что и на что заменять:');
  230. Read(e.b,e2.b);
  231. p5(LL,e,e2);
  232. WriteLn('Список после замены:');
  233. WriteList(LL);
  234. writeln;
  235. WriteLn('Введите что удалять:');
  236. Read(e.b);
  237. p6(LL,e);
  238. WriteLn('Список после одного удаления:');
  239. WriteList(LL);
  240. writeln;
  241. WriteLn('Введите что удалять:');
  242. Read(e.b);
  243. p7(LL,e);
  244. WriteLn('Список после всех удалений:');
  245. WriteList(LL);
  246. writeln;
  247. l1:=p8(LL);
  248. WriteLn('А теперь L1');
  249. WriteList(LL);
  250. writeln;
  251. WriteLn('Введите что удваивать:');
  252. Read(e.b);
  253. p9(LL,e);
  254. WriteLn('Список после:');
  255. WriteList(LL);
  256. writeln;
  257. WriteLn('Средн. арифм.: ',p10(LL,0,1):0:2);
  258. end.