16,748
社区成员
发帖
与我相关
我的任务
分享
uses System.SysUtils, System.Generics.Collections;
procedure StatGrid(const Grid: TStringGrid);
var
D: TDictionary<string, integer>;
S: string;
P: TPair<string, integer>;
i: integer;
begin
D := TDictionary<string, integer>.Create;
for i := Grid.FixedRows to Grid.RowCount - 1 do
begin
S := Grid.Cells[Grid.FixedCols, i];
if D.ContainsKey(S) then D[S] := D[S] + 1 else D.Add(S, 1);
end;
for P in D do
if P.Value = 1 then
writeln(P.Key) // 怎样显示或存储看你的需要
else
writeln(Format('%s:%d', [P.Key, P.Value])); // 怎样显示或存储看你的需要
D.Free;
end;