// PascalABC.NET 3.0, сборка 1073 const sb='bcdfgjklmnpqrstvwxz'; s='Computer programming is a process of computer programs creation'; var i,n:integer; s1,sn,t:string; begin i:=1; while s[i]<>' ' do Inc(i); s1:=Copy(s,1,i-1); n:=Length(s); i:=n; while s[i]<>' ' do Dec(i); sn:=Copy(s,i+1,n-i); t:=''; for i:=1 to Length(s1) do if Pos(s1[i],sb)>0 then t:=t+s1[i]; s1:=t; t:=''; for i:=1 to Length(sn) do if Pos(sn[i],sb)>0 then t:=t+sn[i]; sn:=t; t:=''; for i:=1 to Length(s1) do if Pos(s1[i],sn)>0 then if Pos(s1[i],t)=0 then t:=t+s1[i]; for i:=1 to Length(t) do Write(t[i],' '); Writeln end.
Тестовый прогон: t r
2. "Нормальное" решение
// PascalABC.NET 3.0, сборка 1073 const sb='bcdfgjklmnpqrstvwxz'; s='Computer programming is a process of computer programs creation'; begin var a:=s.ToWords(' '); a[0].Intersect(a[a.Length-1]).Where(x->Pos(x,sb)>0).Println(',') end.
// PascalABC.NET 3.0, сборка 1156 от 30.01.2016 function Avg(a:array[,] of integer):real; begin var s:=0; var k:=0; foreach var e:integer in a do if e>0 then begin s+=e; Inc(k) end; if k>0 then Result:=s/k else Result:=1e-100; end;
begin var A:=MatrixRandom(4,4,-50,50); Writeln(A); Writeln('Среднее арифметическое положительных равно ',Avg(A):0:3); var B:=MatrixRandom(5,5,-30,30); Writeln(B); Writeln('Среднее арифметическое положительных равно ',Avg(B):0:3); var C:=MatrixRandom(4,5,-25,38); Writeln(C); Writeln('Среднее арифметическое положительных равно ',Avg(C):0:3); end.
Тестовое решение: [[35,35,5,-47],[14,34,35,-13],[25,-5,35,-29],[-7,10,-12,12]] Среднее арифметическое положительных равно 24.000 [[-12,-17,-10,19,14],[20,17,-27,-2,16],[-3,-21,30,2,10],[5,-3,-17,-3,18],[0,-26,29,1,-22]] Среднее арифметическое положительных равно 15.083 [[-5,-11,17,-4,15],[15,17,-24,36,15],[-8,-3,-22,28,-25],[-21,6,12,31,-1]] Среднее арифметическое положительных равно 19.200
// PascalABC.NET 3.0, сборка 1073
const
sb='bcdfgjklmnpqrstvwxz';
s='Computer programming is a process of computer programs creation';
var
i,n:integer;
s1,sn,t:string;
begin
i:=1;
while s[i]<>' ' do Inc(i);
s1:=Copy(s,1,i-1);
n:=Length(s); i:=n;
while s[i]<>' ' do Dec(i);
sn:=Copy(s,i+1,n-i);
t:='';
for i:=1 to Length(s1) do
if Pos(s1[i],sb)>0 then t:=t+s1[i];
s1:=t;
t:='';
for i:=1 to Length(sn) do
if Pos(sn[i],sb)>0 then t:=t+sn[i];
sn:=t;
t:='';
for i:=1 to Length(s1) do
if Pos(s1[i],sn)>0 then
if Pos(s1[i],t)=0 then t:=t+s1[i];
for i:=1 to Length(t) do Write(t[i],' ');
Writeln
end.
Тестовый прогон:
t r
2. "Нормальное" решение
// PascalABC.NET 3.0, сборка 1073
const
sb='bcdfgjklmnpqrstvwxz';
s='Computer programming is a process of computer programs creation';
begin
var a:=s.ToWords(' ');
a[0].Intersect(a[a.Length-1]).Where(x->Pos(x,sb)>0).Println(',')
end.
Тестовый прогон:
t,r