Autor Beitrag
LickstheComp
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Do 23.10.08 19:38 
Hallo,
Ich möchte ein Wort prüfen ob es mehr als die hälfte die gleichen Buchstaben enthält.
Ich habe mir gedacht ich prüfe das Wort mit 2 schleifen, aber das Problem ist,
dass die Schleifen in einer Reihenfolge durch das Wort gehen und nicht kreuz und quer.
Möglich wäre es jeden Buchstaben einzeln zu speichern, aber dass finde ich zu aufwendig!
Wisst ihr eine bessere Lösung?
Lg
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Do 23.10.08 19:42 
sortiere die Buchstaben z.B. mit quicksort und prüfe dann mit einer schleife.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Do 23.10.08 19:56 
Hi und :welcome: im Delphi-Forum,

@Boldar: Wozu sortieren :shock: Ich dache nur zählen.. Weiß auch nicht ganz, was das Problem beim geordneten Durchgehen ist. Chaotisches Durchgehen sollte doch keinerlei Vorteile bringen :?: :!:

ausblenden Was hältst du hiervon:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
function CountOccurences(const SubStr, S: String): Integer;
var
  i: Integer;
begin
  result := -1;
  i := 1;
  while i <> 0 do begin
    i := PosEx(SubStr, S, i);
    Inc(result);
  end;
end;

//oder nur für einzelne Buchstaben
function CountOccurences(C: Char; const S: String): Integer;
var
  i: Integer;
begin
  result := 0;
  i := Length(S);
  while i > 0 do
    if S[i] = C then
      Inc(result);
    Dec(i);
  end;
end;


Und dann halt prüfen, ob z.B. CountOccurences('*', 'B*e*e*e*d') >= Length('B*e*e*e*d') div 2 ist :nixweiss:

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Do 23.10.08 20:07 
user profile iconHidden: Das prüft nur, ob ein bestimmter Buchstabe oft vorkommt. Gefragt ist aber, ob irgendein Buchstabe die Mehrheit einnimmt:

user profile iconLickstheComp hat folgendes geschrieben Zum zitierten Posting springen:
Ich möchte ein Wort prüfen ob es mehr als die hälfte die gleichen Buchstaben enthält.


Wahrscheinlich ist nur Sortieren oder Speichern aller Zeichen möglich.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Do 23.10.08 20:14 
Ist mir auch gerade aufgefallen :autsch: Sry :)

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)