Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Программирование и базы данных (http://forum.oszone.net/forumdisplay.php?f=21)
-   -   Вероятность появления элемента Snringgrid (http://forum.oszone.net/showthread.php?t=301512)

Alibaba.bu 22-06-2015 14:41 2521095

Вероятность появления элемента Snringgrid
 
Доброго времени суток! Есть программка, она считает количество появлений в тексте всех элементов, нужно организовать в данном коде подсчет вероятности появления этих символом))) Помогите пожалуйста))
procedure TForm1.Button1Click(Sender: TObject);
var
s : string;
Ch : Char;
Counts : array[Char] of Integer;
i,j,ColSort: Integer;

begin
s := AnsiUpperCase(Edit1.Text);
ZeroMemory(@Counts, SizeOf(Counts));
for i := 1 to Length(s) do Inc(Counts[s[i]]);
j := 0;
for Ch := Low(Char) to High(Char) do
if (Counts[Ch] > 0)and(Ch<>' ') then
begin
StringGrid2.Cells[0,j+1]:=Ch;
StringGrid2.Cells[1,j+1]:=inttostr(Counts[Ch]);
Inc(j);
StringGrid2.RowCount:=StringGrid2.RowCount+1;
end;
StringGrid2.RowCount:=StringGrid2.RowCount-1;
begin
ColSort:=1;
With StringGrid2 do begin
for i:=FixedRows to RowCount-1 do
for j:=FixedRows to RowCount-1 do
if StrToIntDef(Cells[ColSort,i],0)>StrToIntDef(Cells[ColSort,j],0) then begin
s:=Rows[i].Text;
Rows[i].Text:=Rows[j].Text;
Rows[j].Text:=s;
end;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid2.Cells[0,0]:=('Символ');
StringGrid2.Cells[1,0]:=('Количество');
StringGrid2.Cells[2,0]:=('Вероятность');
end;
end.

lxa85 26-06-2015 00:52 2522597

Alibaba.bu, прикрепите архив проекта и укажите версию Delphi.


Время: 17:40.

Время: 17:40.
© OSzone.net 2001-