Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program q;
- uses crt;
- type
- s1=^ukaz1;
- ukaz1=record
- data:integer;
- next,back:s1;
- end;
- s2=^ukaz2;
- ukaz2=record
- data:integer;
- next:s2;
- end;
- var
- spis1,posl,u,u1,perv1:s1;
- spis2,u2,perv2:s2;
- ch:char;
- function PROST(x:s1):integer;
- var
- flag:boolean;
- i:integer;
- begin
- if x^.data=2 then flag:=true
- else if not odd(x^.data) then flag:=false
- else begin
- flag := true;
- for i := 2 to x^.data-1 do
- if x^.data mod i = 0 then flag:=false
- end;
- if flag then PROST:=x^.data else PROST:=0;
- end;
- begin
- clrscr;
- randomize;
- new(spis1);
- spis1^.data:=random(99);
- spis1^.next:=nil;
- spis1^.back:=nil;
- u:=spis1;
- while ch<>chr(32) do begin
- new(u1);
- u1^.data:=random(99);
- u1^.next:=nil;
- u^.next:=u1;
- u1^.back:=u;
- u:=u1;
- ch:=readkey;
- end;
- perv1:=spis1;
- writeln;
- u1^.next:=spis1;
- posl:=u1;
- spis1^.back:=posl;
- u:=posl;
- while spis1<>u do begin
- write(spis1^.data:3);
- spis1:=spis1^.next;
- end;
- if PROST(spis1)=0 then begin
- new(spis2);
- spis2^.next:=nil;
- spis2^.data:=0;
- spis1:=spis1^.next;
- end else begin
- new(spis2);
- spis2^.next:=nil;
- spis2^.data:=spis1^.data;
- spis1:=spis1^.next;
- end;
- perv2:=spis2;
- spis1:=perv1;
- while spis1^.next<>u do begin
- if PROST(spis1)=0 then spis1:=spis1^.next
- else begin
- new(u2);
- u2^.next:=nil;
- u2^.data:=spis1^.data;
- spis2^.next:=u2;
- spis2:=u2;
- spis1:=spis1^.next;
- end;
- end;
- spis2:=perv2;
- writeln;
- while spis2<>nil do begin
- write(spis2^.data:3);
- spis2:=spis2^.next;
- end;
- writeln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement