unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
Memo1: TMemo;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mas: array [1..1065] of Byte;
mas2: array [1..1065] of Integer;
massiv, massiv2: array [1..2,1..500] of Byte;
massiv3, massiv4: array [1..2,1..500] of Integer;
frequency: Real;
K, I, J: Integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
for I := 1 to 1065 do
mas2[i]:=0;
for I := 1 to 2 do
for J := 1 to 500 do
begin
massiv[I,J] := 0;
massiv2[I,J] := 0;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Col, Num, x,y,n: Integer;
Str, s, ss: string;
T: Boolean;
begin
K := 0;
// Записываем цифры из текста в массив
for I := 0 to Memo1.Lines.Count - 1 do
begin
Str:=Memo1.Lines[i];
J := 1;
while (j<=Length(Str)) do
begin
if ((Str[J] <> ' ') and (Str[J] <> ',') and (Str[J] <> '.') and
(Str[J] <> '-')and (Str[J] <> ':')) then
begin
Inc(K);
S := Copy(Str, J, 2);
Mas[K] := StrToInt(s);
J := J + 2;
end
else
Inc(J);
end;
end;
Num := K;
// Подсчитываем сколько раз каждая цифра встречается в исходном тексте
for I := 1 to K do
begin
X := mas[i];
Col := 0;
for J := 1 to K do
if (X = mas[J]) then
Inc(Col);
massiv[1, I] := X;
massiv[2, I] := Col;
end;
for I := 1 to K do
begin
X := massiv[1, I];
Y := I;
J := 1;
while J <= K do
begin
if (massiv[1,j] = X) and (J <> I) then
begin
massiv[1, J] := 0;
massiv[2, J] := 0;
end;
Inc(J)
end
end;
Col := 0;
for I := 1 to K do
if (massiv[1, I] <> 0)then
begin
Inc(Col);
massiv2[1, Col] := massiv[1, I];
massiv2[2, Col] := massiv[2, I]
end;
StringGrid1.ColCount := Col;
for I := 1 to K do
begin
StringGrid1.Cells[I-1, 0] := IntToStr(massiv2[1,I]);
StringGrid1.Cells[I-1, 1] := IntToStr(massiv2[2,I]);
Frequency := massiv2[2,I] / Num;
StringGrid1.Cells[I-1, 2] := FloatToStrF(Frequency, fffixed, 5, 4);
end;
// Подсчет биграмм
for I := 0 to Memo1.Lines.Count - 1 do
begin
Str := Memo1.Lines[i];
J := 1;
while (J <= Length(Str)) do
begin
if ((Str[J] <> ' ') and (Str[J] <> ',') and (Str[J] <> '.') and
(Str[J] <> '-') and (Str[J] <> ':') and (Str[J + 1] <> ' ')) then
begin
s := Copy(Str, J, 5);
for N := 1 to 5 do
if ((s[N] = ' ') or (s[N] = ',') or (s[N] = ':') or (s[N] = '-'))then
Delete(s, N, 1);
if Length(s) = 4 then
begin
Inc(K);
mas2[K] := StrToInt(s);
end;
J := J + 2;
end
else
Inc(J);
end;
end;
StringGrid2.ColCount := K;
Num := K;
for I := 1 to k do
begin
X := mas2[i];
Col := 0;
for J := 1 to k do
if (X = mas2[J]) then
Inc(Col);
massiv3[1, I] := X;
massiv3[2, I] := Col;
end;
for I := 1 to K do
begin
X := massiv3[1, I];
Y := I;
J := 1;
while J <= K do
begin
if (massiv3[1, J] = x) and (J <> I) then
begin
massiv3[1, J] := 0;
massiv3[2, J] := 0;
end;
Inc(J);
end;
end;
Col := 0;
for I := 1 to K do
if (massiv3[1, I] <> 0)then
begin
Inc(Col);
massiv4[1, Col] := massiv3[1, I];
massiv4[2, Col] := massiv3[2, I];
end;
StringGrid2.ColCount:=Col;
for I := 1 to K do
begin
StringGrid2.Cells[I-1, 0] := IntToStr(massiv4[1, I]);
StringGrid2.Cells[I-1, 1] := IntToStr(massiv4[2, I]);
Frequency := massiv4[2, I] / num;
StringGrid2.Cells[I-1, 2] := FloatToStrF(Frequency, fffixed, 5, 4);
end;
end;
end.