// PascalABC.NET 3.1, сборка 1200 от 13.03.2016 function IsPrime(n:integer):boolean; begin if n<4 then Result:=True else begin var found:= (n mod 2 = 0); var p:=3; while (not found) and (sqr(p)<=n) do begin found:=(n mod p = 0); p+=2 end; Result:=not found end end;
begin Writeln('k=',ArrRandom(ReadInteger('n='),1,999).Println. Where(x->IsPrime(x)).Count) end.
// PascalABC.NET 3.1, сборка 1200 от 13.03.2016 procedure IsPrime(n:integer; var res:boolean); begin if n<4 then res:=True else begin var found:= (n mod 2 = 0); var p:=3; while (not found) and (sqr(p)<=n) do begin found:=(n mod p = 0); p+=2 end; res:=not found end end;
begin var a:=ArrRandom(ReadInteger('n='),1,999); a.Println; var k:=0; var prime:boolean; foreach var e in a do begin IsPrime(e,prime); if Prime then Inc(k) end; Writeln('k=',k) end.
Попробуй Program PascalGuru; var s:string; f,t:text; function preobr(s:string):string;var i,j,p,n,sered:integer; gl,zp,slovo:string; m:array [1..80] of string;beginzp:='!?*,.'; gl:='аоуыэяеёюи'; p:=pos(' ',s); i:=0; repeat inc(i); slovo:=copy(s,1,p-1); m[i]:=slovo; delete(s,1,p); p:=pos(' ',s); until p=0; n:=i+1; m[n]:=s; for i:=1 to n do begin s:=m[i]; if pos(s[length(s)],zp)<>0 then p:=length(s)-1 else p:=length(s); sered:=(p div 2)+1; if (not odd(p)) or (p<3) then continue; if pos(s[1],gl)=0 then continue; if pos(s[sered],gl)=0 then continue; if pos(s[p],gl)=0 then continue; s[1]:=UpCase(s[1]); s[sered]:=UpCase(s[sered]); s[p]:=UpCase(s[p]); m[i]:=s+'('+s[1]+','+s[sered]+','+s[p]+')'; end; s:=''; for i:=1 to n do s:=s+m[i]+' '; preobr:=s;end; beginassign(f,'input.txt'); reset(f);assign(t,'output.txt'); rewrite(t); while not eof(f) do begin readln(f,s); writeln(t, preobr(s) ); end; writeln('Файл успешно записан...'); close(f);close(t);readln;end.
// PascalABC.NET 3.1, сборка 1200 от 13.03.2016
function IsPrime(n:integer):boolean;
begin
if n<4 then Result:=True
else begin
var found:= (n mod 2 = 0);
var p:=3;
while (not found) and (sqr(p)<=n) do
begin
found:=(n mod p = 0);
p+=2
end;
Result:=not found
end
end;
begin
Writeln('k=',ArrRandom(ReadInteger('n='),1,999).Println.
Where(x->IsPrime(x)).Count)
end.
Тестовое решение:
n= 10
401 828 780 444 694 965 23 341 673 875
k=3
2. А вот так это пишется с процедурой
// PascalABC.NET 3.1, сборка 1200 от 13.03.2016
procedure IsPrime(n:integer; var res:boolean);
begin
if n<4 then res:=True
else begin
var found:= (n mod 2 = 0);
var p:=3;
while (not found) and (sqr(p)<=n) do
begin
found:=(n mod p = 0);
p+=2
end;
res:=not found
end
end;
begin
var a:=ArrRandom(ReadInteger('n='),1,999); a.Println;
var k:=0;
var prime:boolean;
foreach var e in a do begin
IsPrime(e,prime);
if Prime then Inc(k)
end;
Writeln('k=',k)
end.
Тестовое решение:
n= 12
199 43 71 365 417 904 170 212 694 103 161 689
k=4
function preobr(s:string):string;var i,j,p,n,sered:integer; gl,zp,slovo:string; m:array [1..80] of string;beginzp:='!?*,.'; gl:='аоуыэяеёюи'; p:=pos(' ',s); i:=0; repeat inc(i); slovo:=copy(s,1,p-1); m[i]:=slovo; delete(s,1,p); p:=pos(' ',s); until p=0; n:=i+1; m[n]:=s; for i:=1 to n do begin s:=m[i]; if pos(s[length(s)],zp)<>0 then p:=length(s)-1 else p:=length(s); sered:=(p div 2)+1; if (not odd(p)) or (p<3) then continue; if pos(s[1],gl)=0 then continue; if pos(s[sered],gl)=0 then continue; if pos(s[p],gl)=0 then continue; s[1]:=UpCase(s[1]); s[sered]:=UpCase(s[sered]); s[p]:=UpCase(s[p]); m[i]:=s+'('+s[1]+','+s[sered]+','+s[p]+')'; end; s:=''; for i:=1 to n do s:=s+m[i]+' '; preobr:=s;end;
beginassign(f,'input.txt'); reset(f);assign(t,'output.txt'); rewrite(t); while not eof(f) do begin readln(f,s); writeln(t, preobr(s) ); end; writeln('Файл успешно записан...'); close(f);close(t);readln;end.