Дана символьная строка. Слово — последовательность символов между пробелами, не содержащая пробелы внутри себя. определить количество слов заданной длины — Pascal(Паскаль)

uses
  crt;
var
  s,temp:string;
  i,c,k:integer;
begin
  clrscr;
  writeln('Vvedite stroku...');
  readln(s);
  writeln('Dlina...');
  readln(k);
  temp:='';
  c:=0;
  for i:=1 to length(s) do
  begin
    if s[i]<>' ' then
      temp:=temp+s[i];
    if ((s[i]=' ') or (i=length(s))) and (temp<>'') then
    begin
      if Length(temp)=k then
        inc(c);
      temp:='';
    end;
  end;
  Writeln('Result: ',c)
end.

Leave a Comment

+ 24 = 28