Дана строка,заканчивающаяся точкой. Подсчитать,сколько слов в строке — Pascal(Паскаль)

var
s:string;
a,i,x,y:integer;
begin
readln(s);
a:=length(s);
For i:=1 to a do
begin
x:=pos(' ',s);
if x>0 then
begin
delete(s,1,x);
inc(y);
end;
end;
if length(s)>0 then inc(y);
writeln(y);
end.

Вариант 2

var
s:string;
a,i,x,y:integer;
begin
readln(s);
a:=length(s);
For i:=a downto 1 do
if (s[i]=' ') and (s[i]=s[i-1]) then delete(s,i,1);
For i:=1 to a do
begin
x:=pos(' ',s);
if x>0 then
begin
delete(s,1,x);
inc(y);
end;
end;
if length(s)>0 then inc(y);
writeln(y);
end.

Leave a Comment

85 − = 78