Advertisement
ADEPT_VANEYVA

[RU] Инфа #1 на 12.15

Dec 13th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.80 KB | None | 0 0
  1. program q;
  2. uses crt;
  3. type
  4.   s1=^ukaz1;
  5.   ukaz1=record
  6.     data:integer;
  7.     next,back:s1;
  8.   end;
  9.   s2=^ukaz2;
  10.   ukaz2=record
  11.     data:integer;
  12.     next:s2;
  13.   end;
  14. var
  15.   spis1,posl,u,u1,perv1:s1;
  16.   spis2,u2,perv2:s2;
  17.   ch:char;
  18. function PROST(x:s1):integer;
  19. var
  20.   flag:boolean;
  21.   i:integer;
  22. begin
  23.   if x^.data=2 then flag:=true
  24.          else if not odd(x^.data) then flag:=false          
  25.          else  begin                
  26.               flag := true;                
  27.               for i := 2 to x^.data-1 do                
  28.               if x^.data mod i = 0 then flag:=false                
  29.               end;
  30.   if flag then PROST:=x^.data else PROST:=0;
  31. end;
  32. begin
  33.   clrscr;
  34.   randomize;
  35.   new(spis1);
  36.   spis1^.data:=random(99);
  37.   spis1^.next:=nil;
  38.   spis1^.back:=nil;
  39.   u:=spis1;
  40.   while ch<>chr(32) do begin
  41.     new(u1);
  42.     u1^.data:=random(99);
  43.     u1^.next:=nil;
  44.     u^.next:=u1;
  45.     u1^.back:=u;
  46.     u:=u1;
  47.     ch:=readkey;
  48.   end;
  49.   perv1:=spis1;
  50.   writeln;
  51.   u1^.next:=spis1;
  52.   posl:=u1;
  53.   spis1^.back:=posl;
  54.   u:=posl;
  55.   while spis1<>u do begin
  56.     write(spis1^.data:3);
  57.     spis1:=spis1^.next;
  58.   end;
  59.  
  60.   if PROST(spis1)=0 then begin
  61.     new(spis2);
  62.     spis2^.next:=nil;
  63.     spis2^.data:=0;
  64.     spis1:=spis1^.next;
  65.   end else begin
  66.     new(spis2);
  67.     spis2^.next:=nil;
  68.     spis2^.data:=spis1^.data;
  69.     spis1:=spis1^.next;
  70.     end;
  71.   perv2:=spis2;
  72.   spis1:=perv1;
  73.   while spis1^.next<>u do begin
  74.     if PROST(spis1)=0 then spis1:=spis1^.next
  75.     else begin
  76.       new(u2);
  77.       u2^.next:=nil;
  78.       u2^.data:=spis1^.data;
  79.       spis2^.next:=u2;
  80.       spis2:=u2;
  81.       spis1:=spis1^.next;
  82.     end;
  83.   end;
  84.  
  85. spis2:=perv2;
  86. writeln;
  87.   while spis2<>nil do begin
  88.     write(spis2^.data:3);
  89.     spis2:=spis2^.next;
  90.   end;
  91. writeln;
  92. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement