unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

const N=100;

Type A=array[1..N] of string;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Edit1.Clear;
  Edit2.Clear;
end;

Function slova(var st: string): string;
var i: integer;
begin
  if st='' then Exit;
  Result:='';
  while st[1]=#32 do delete(st,1,1);
  if st='' then Exit;
  i:=1;
  while (st[i]<>#32) and (Result<st) do begin
    Result:=Result+st[i];
    i:=i+1;
  end;
end;      

Function p(var str: string): integer;
var i,j,k: integer; b: A;
begin
  Result:=0;
  i:=1;
  while (str<>'') and (i<=N) do begin
    b[i]:=slova(str);
    delete(str,1,length(b[i]));
    i:=i+1;
  end;
  i:=1;
  while (b[i]<>'') and (i<=N) do begin
    j:=1;
    k:=0;
    while j<=length(b[i]) do begin
      if (b[i][j]='1') or (b[i][j]='0') then k:=k+1;
      j:=j+1;
    end;
    if (k=length(b[i])) and (length(b[i])=5) then Result:=Result+1;
    i:=i+1;
  end;  
end;

procedure TForm1.Button1Click(Sender: TObject);
var str: string;
begin
  str:=Edit1.Text;
  Edit2.Text:=IntToStr(p(str));
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
var str: string;
begin
  if Key=#13 then begin
    str:=Edit1.Text;
    Edit2.Text:=IntToStr(p(str));
  end;  
end;

end.
