Anagrams: Difference between revisions
Content added Content deleted
MaiconSoft (talk | contribs) |
MaiconSoft (talk | contribs) |
||
Line 1,934:
begin
if s1.Length <> s2.Length then
exit(
Result := Sort(s1) = Sort(s2);
end;
Line 1,945 ⟶ 1,947:
words := s.Substring(5);
Result := TryStrToInt(sCount, Count);
end;
function CompateLength(List: TStringList; Index1, Index2: Integer): Integer;
result := List[Index1].Length - List[Index2].Length;
Result := CompareText(Sort(List[Index2]), Sort(List[Index1]));
end;
var
Dict: TStringList;
i, j, Count, MaxCount, WordLength, Index: Integer;
words: string;
StopWatch: TStopwatch;
begin
Dict := TStringList.Create;▼
dict.LoadFromFile('unixdict.txt');▼
StopWatch := TStopwatch.Create;
StopWatch.Start;
▲ Dict := TStringList.Create();
▲ begin
Continue;▼
Dict.CustomSort(CompateLength);
Count := 0;▼
words := Dict[i];▼
Index := 0;
words := Dict[Index];
if (not Dict[j].IsEmpty) and IsAnagram(Dict[i], Dict[j]) then▼
Count :=
▲ words := words + ',' + Dict[j];
while Index + Count
begin
inc(Count);▼
end;▼
begin
▲ if Count > 0 then
end
else
begin
▲ Dict[i] := '';
Dict[Index] := format('%.4d', [Count]) + ',' + words;
end;
Line 1,985 ⟶ 1,997:
Dict.Sort;
while Dict[0].IsEmpty do
Dict.Delete(0);
StopWatch.Stop;
Split(Dict[Dict.count - 1], MaxCount, words);
writeln(#10'The anagrams that contain the most words, has ', MaxCount, ' words:'#10);
writeln('Words found:'#10);
Writeln(' ', words);
for i := Dict.Count - 2 downto 0 do
Line 2,001 ⟶ 2,015:
Split(Dict[i], Count, words);
if Count = MaxCount then
Writeln(' ', words)
else
Break;
Line 2,014 ⟶ 2,028:
{{out}}
<pre>
Time pass
The anagrams that contain the most words, has 5 words:
Words found:
trace,crate,cater,carte,caret
regal,glare,large,lager,alger
neal,lean,elan,lane,lena
glean,angel
</pre>
|