В некотором тексте определить отрицательные частицы не и ни. Вывести эти частицы на экран и определить их количество — Pascal(Паскаль)

например:Ни одна система не остается неизменной

uses
  crt;
const
  dividers=[' ',',','.',';',':','-','=','+'];
var
  s,temp:string;
  i:integer;
begin
  clrscr;
  writeln('Введите строку:');
  readln(s);
  temp:='';
  {пробегаем всю строку посимвольно}
  for i:=1 to length(s) do
  begin
    if not (s[i] in dividers) then
      temp:=temp+s[i];
    if (s[i] in dividers) or (i=length(s)) then
      if temp<>'' then
      begin
        if (temp='Не') or(temp='НЕ') or(temp='нЕ') or(temp='не') or(temp='Ни') or(temp='НИ') or (temp='нИ') or(temp='ни') then
          write(temp,' ');
        temp:='';
      end;
  end
end.

Вариант 2

uses
  crt;
const
  dividers=[' ',',','.',';',':','-','=','+'];
var
  s,temp:string;
  i,c:integer;
begin
  clrscr;
  writeln('Введите строку:');
  readln(s);
  temp:='';
  c:=0;
  {пробегаем всю строку посимвольно}
  for i:=1 to length(s) do
  begin
    if not (s[i] in dividers) then
      temp:=temp+s[i];
    if (s[i] in dividers) or (i=length(s)) then
      if temp<>'' then
      begin
        if (LowerCase(temp)='не') or (LowerCase(temp)='ни') then
          inc(c);
        temp:='';
      end;
  end;
  if c<>0 then
    writeln('Встречаются ',c,' раз(а).')
  else
    writeln('В заданном тексте эти частицы не встречаются!')
end.

Leave a Comment

+ 30 = 38