Дана строка символов. Определить количество слов в строке — Pascal(Паскаль)

uses crt;
var i,l,k,j:longint;
    a:string;
begin
Clrscr;
Write('Vvedite stroku: ');
Readln(a);
l:=length(a);
for i:=1 to l do
 if (a[i]=' ') and (a[i+1]=' ') then
  inc(j)
 else
  a[i-j]:=a[i];
 l:=l-j;
 if a[1]=' 'then
  begin
   delete(a,1,1);
   l:=l-1;
  end;
 if a[l]<>' ' then
  begin
   inc(l);
   a[l]:=' ';
  end;
for i:=1 to l do
 if a[i]=' 'then
  inc(k);
Write('Kol-vo slov: ',k);
Readln;
end.

Leave a Comment

+ 72 = 81