Advertisement
dikdack

Untitled

Dec 16th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 8.97 KB | None | 0 0
  1. program lab7;
  2.  
  3. {$APPTYPE CONSOLE}
  4. uses crt;
  5.  
  6. type
  7.   Rec1=Record
  8.     tema:string;
  9.     num:integer;
  10.     raz:string;
  11.     zap:integer;
  12.     next1:^Rec1;
  13.   end;
  14.     Rec4=Record
  15.     raz:string;
  16.     zap:integer;
  17.     next4:^Rec4;
  18.   end;
  19.   Rec3=Record
  20.     num:integer;
  21.     next3:^Rec3;
  22.     next4:^Rec4;
  23.   end;
  24.   Rec2=Record
  25.     tema:string;
  26.     next2:^Rec2;
  27.     next3:^Rec3;
  28.   end;
  29.  
  30. var
  31.   tmpM, HeadM: ^Rec1;
  32.   tmpT, HeadT: ^Rec2;
  33.   tmpN, HeadN,tmpk: ^Rec3;
  34.   tmp1: ^Rec4;
  35.   z, numN, zapN, K, L, I, J, count: integer;
  36.   temaN, temaP, razN: string;
  37.   mas: array [1..100] of integer;
  38.  
  39. function check1(temaN:string):boolean;
  40. begin
  41.   tmpT:=HeadT;
  42.   check1:=False;
  43.   while tmpT<>nil do
  44.   begin
  45.     if tmpT^.tema = temaN then
  46.     begin
  47.       check1:=True;
  48.       exit;
  49.     end;
  50.     tmpT:=tmpT^.next2;
  51.   end;
  52. end;
  53.  
  54. function check2(numP:integer):boolean;
  55. begin
  56.   tmpN:=HeadN;
  57.   check2:=False;
  58.   while tmpN<>nil do
  59.   begin
  60.     if tmpN^.num = numP then
  61.     begin
  62.       check2:=True;
  63.       exit;
  64.     end;
  65.     tmpN:=tmpN^.next3;
  66.   end;
  67. end;
  68.  
  69. procedure SHOW3();
  70. begin
  71.   tmpM:=HeadM;
  72.   while tmpM<>nil do
  73.   begin
  74.     if tmpM^.zap > 10 then
  75.     begin
  76.       writeln('| ' ,tmpM^.tema:14, ' | ',tmpM^.num:8, ' | ', tmpM^.raz:14, ' | ',tmpM^.zap:8, ' |');
  77.       writeln( '|-------------------------------------------------------|');
  78.     end;
  79.     tmpM:= tmpM^.next1;
  80.   end;
  81. end;
  82.  
  83. procedure SHOW4(temaP:string);
  84. begin
  85.   tmpM:=HeadM;
  86.   while tmpM<>nil do
  87.   begin
  88.     if tmpM^.tema = temaP then
  89.     begin
  90.       writeln('| ' ,tmpM^.tema:14, ' | ',tmpM^.num:8, ' | ', tmpM^.raz:14, ' | ',tmpM^.zap:8, ' |');
  91.      writeln( '|-------------------------------------------------------|');
  92.     end;
  93.     tmpM:= tmpM^.next1;
  94.   end;
  95. end;
  96.  
  97.  
  98. procedure NEWW(temaN,razN:string;numN,zapN:integer);
  99. begin
  100.   new(tmpM);
  101.   tmpM^.next1:= HeadM;
  102.   HeadM:= tmpM;
  103.   tmpM^.tema:= temaN;
  104.   tmpM^.num:= numN;
  105.   tmpM^.raz:= razN;
  106.   tmpM^.zap:= zapN;
  107.   if check1(temaN) then
  108.   begin
  109.     tmpT:= HeadT;
  110.     while tmpT^.tema <> temaN do
  111.     begin
  112.       tmpT:=tmpT^.next2;
  113.     end;
  114.    
  115.     if check2(numN) then
  116.     begin
  117.       tmpN:=HeadN;
  118.       while tmpN^.num <> numN do
  119.       begin
  120.         tmpN:=tmpN^.next3;
  121.       end;
  122.       new(tmp1);
  123.       tmp1^.next4:=tmpN^.next4;
  124.       tmpN^.next4:=tmp1;
  125.       tmp1^.raz:= razN;
  126.       tmp1^.zap:= zapN;
  127.     end
  128.     else
  129.     begin
  130.       new(tmpN);
  131.       tmpN^.next3:= HeadN;
  132.       HeadN:= tmpN;
  133.       tmpN^.num:= numN;
  134.       new(tmp1);
  135.       tmp1^.next4:=tmpN^.next4;
  136.       tmpN^.next4:=tmp1;
  137.       tmp1^.raz:= razN;
  138.       tmp1^.zap:= zapN;
  139.     end;
  140.   end
  141.   else
  142.   begin
  143.     new(tmpT);
  144.     tmpT^.next2:= HeadT;
  145.     HeadT:= tmpT;
  146.     tmpT^.tema:= temaN;
  147.     new(tmpk);
  148.     tmpk^.next3:=tmpT^.next3;
  149.     tmpT^.next3:=tmpk;
  150.     tmpk^.num:= numN;
  151.     new(tmp1);
  152.     tmp1^.next4:=tmpk^.next4;
  153.     tmpk^.next4:=tmp1;
  154.     tmp1^.raz:= razN;
  155.     tmp1^.zap:= zapN;
  156.   end;
  157. end;
  158.  
  159. procedure Numb ();
  160. begin
  161.   count := 0;
  162.   tmpM := HeadM;
  163.   while tmpM <> nil do
  164.   begin
  165.     inc(count);
  166.     tmpM := tmpM^.next1;
  167.   end;
  168. end;
  169.  
  170. //////////////////////////////////////////////
  171. begin
  172.   HeadM := nil;
  173.   HeadT := nil;
  174.   HeadN := nil;
  175.  
  176.   while true do
  177.   begin
  178.     textcolor(10);
  179.     writeln('');
  180.     writeln('******************** МЕНЮ ********************');
  181.     writeln('|--------------------------------------------|');
  182.     write('| '); textcolor(13); write('Выберите:                                  '); textcolor(10); writeln('|');
  183.     write('| '); textcolor(13); write('0. Завершение работы                       '); textcolor(10); writeln('|');
  184.     write('| '); textcolor(13); write('1. Добавление сведений                     '); textcolor(10); writeln('|');
  185.     write('| '); textcolor(13); write('2. Просмотр разделов с числом записей > 10 '); textcolor(10); writeln('|');
  186.     write('| '); textcolor(13); write('3. Просмотр всей таблицы                   '); textcolor(10); writeln('|');
  187.     write('| '); textcolor(13); write('4. Просмотр темы                           '); textcolor(10); writeln('|');
  188.     write('| '); textcolor(13); write('5. Вывод отсортированной таблицы           '); textcolor(10); writeln('|');
  189.     writeln('|--------------------------------------------|');
  190.     writeln('**********************************************');
  191.     write('Ваш выбор: ');
  192.     textcolor(15);
  193.     readln(z);
  194.     textcolor(10);
  195.     if z = 0 then
  196.       exit;
  197.     if z = 2 then
  198.     begin
  199.       writeln('|-------------------------------------------------------|');
  200.       write('|');
  201.       textcolor(13);
  202.       write('Формат:| тема | номер раздела | раздел | число записей'); textcolor(10); writeln(' |');
  203.       writeln('|-------------------------------------------------------|');
  204.       writeln('************************ ТАБЛИЦА ************************');
  205.       SHOW3();
  206.       writeln('*********************************************************');
  207.     end;
  208.     if z = 3 then
  209.     begin
  210.       tmpM:=HeadM;
  211.       writeln('|-------------------------------------------------------|');
  212.       write('|');
  213.       textcolor(13);
  214.       write('Формат:| тема | номер раздела | раздел | число записей'); textcolor(10); writeln(' |');
  215.       writeln('|-------------------------------------------------------|');
  216.       writeln('************************ ТАБЛИЦА ************************');
  217.       while tmpM<>nil do
  218.       begin
  219.         writeln('| ' ,tmpM^.tema:14, ' | ',tmpM^.num:8, ' | ', tmpM^.raz:14, ' | ',tmpM^.zap:8, ' |');
  220.         writeln( '|-------------------------------------------------------|');
  221.         tmpM:= tmpM^.next1;
  222.       end;
  223.       writeln('*********************************************************');
  224.     end;
  225.     if z = 4 then
  226.     begin
  227.       write('Введите название темы: ');
  228.       textcolor(15);
  229.       readln  (temaP);
  230.       textcolor(10);
  231.       writeln('|-------------------------------------------------------|');
  232.       write('|');
  233.       textcolor(13);
  234.       write('Формат:| тема | номер раздела | раздел | число записей'); textcolor(10); writeln(' |');
  235.       writeln('|-------------------------------------------------------|');
  236.       writeln('************************ ТАБЛИЦА ************************');
  237.       SHOW4(temaP);
  238.       writeln('*********************************************************');
  239.     end;
  240.     if z = 5 then
  241.     begin
  242.       writeln('|-------------------------------------------------------|');
  243.       write('|');
  244.       textcolor(13);
  245.       write('Формат:| тема | номер раздела | раздел | число записей'); textcolor(10); writeln(' |');
  246.       writeln('|-------------------------------------------------------|');
  247.       writeln('************************ ТАБЛИЦА ************************');
  248.       Numb();
  249.       tmpM := HeadM;
  250.       i := 1;
  251.       while tmpM <> nil do
  252.       begin
  253.         mas[i] := tmpM^.zap;
  254.         tmpM := tmpM^.next1;
  255.         inc(i);
  256.       end;
  257.       K := 1;
  258.       for I
  259.       := 1 to count - 1 do
  260.         begin
  261.              K:= I;
  262.              for J := I + 1 to count do
  263.                if mas[J] < mas[K] then K := J;
  264.                L:=mas[I];
  265.                mas[I] := mas[K];
  266.                mas[K] := L;
  267.         end;
  268.         for i := 1 to count do
  269.         begin
  270.           tmpM:=HeadM;
  271.           while tmpM<>nil do
  272.           begin
  273.             if tmpM^.zap = mas[i] then
  274.             begin
  275.               writeln('| ' ,tmpM^.tema:14, ' | ',tmpM^.num:8, ' | ', tmpM^.raz:14, ' | ',tmpM^.zap:8, ' |');
  276.               writeln( '|-------------------------------------------------------|');
  277.               break;
  278.             end;
  279.             tmpM:= tmpM^.next1;
  280.           end;
  281.         end;
  282.         writeln('*********************************************************');
  283.     end;
  284.     if z = 1 then
  285.     begin
  286.       textcolor(10);
  287.       writeln('**********************************************');
  288.       write('|'); textcolor(13); write('Название темы:               '); textcolor(10); write('|');
  289.       textcolor(15);
  290.       readln(temaN);
  291.       textcolor(10);
  292.       write('|'); textcolor(13); write('Номер раздела:               '); textcolor(10); write('|');
  293.       textcolor(15);
  294.       readln(numN);
  295.       textcolor(10);
  296.       write('|'); textcolor(13); write('Название раздела:            '); textcolor(10); write('|');
  297.       textcolor(15);
  298.       readln(razN);
  299.       textcolor(10);
  300.       write('|'); textcolor(13); write('Число записей в разделе:     '); textcolor(10); write('|');
  301.       textcolor(15);
  302.       readln(zapN);
  303.       textcolor(10);
  304.       writeln('**********************************************');
  305.       NEWW(temaN,razN,numN,zapN);
  306.     end;
  307.     writeln('');
  308.   end;
  309. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement