Добавил:
Fragga
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:PascalDelphi / Многие готовые лабы за 1&2 сем. от Колесниковой М.Д. / L3Pr3 / Unit1
.pas unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Edit2: TEdit;
Label4: TLabel;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function GetSubStr(st:string;n:integer):string;
var i,p:integer;
begin for i:=1 to n-1 do
begin p:=pos(' ',st);st:=copy(st,p+1,length(st)-p) end;
p:=pos(' ',st);{найти конец нужной подстроки}
if p <> 0 then result:=copy(st,1,p-1)
else result:=st
end;
procedure TForm1.Button1Click(Sender: TObject);
const nn=20;
type size=1..nn;
var a:array[size]of integer;
i,n,imax:size;
max:integer;
begin
n:=StrToInt(Edit1.text);
for i:=1 to n do a[i]:=StrToInt(GetSubStr(Edit2.text,i));
max:=a[1]; imax:=1;
for i:=1 to n do
if a[i] > max then begin max:=a[i];imax:=i end;
Label4.Caption:='max='+IntToStr(max);
Label5.Caption:='indexmax='+IntToStr(imax);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close
end;
end.
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Edit2: TEdit;
Label4: TLabel;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function GetSubStr(st:string;n:integer):string;
var i,p:integer;
begin for i:=1 to n-1 do
begin p:=pos(' ',st);st:=copy(st,p+1,length(st)-p) end;
p:=pos(' ',st);{найти конец нужной подстроки}
if p <> 0 then result:=copy(st,1,p-1)
else result:=st
end;
procedure TForm1.Button1Click(Sender: TObject);
const nn=20;
type size=1..nn;
var a:array[size]of integer;
i,n,imax:size;
max:integer;
begin
n:=StrToInt(Edit1.text);
for i:=1 to n do a[i]:=StrToInt(GetSubStr(Edit2.text,i));
max:=a[1]; imax:=1;
for i:=1 to n do
if a[i] > max then begin max:=a[i];imax:=i end;
Label4.Caption:='max='+IntToStr(max);
Label5.Caption:='indexmax='+IntToStr(imax);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close
end;
end.