Einzelnen Beitrag anzeigen

Benutzerbild von Wormid
Wormid

Registriert seit: 26. Aug 2003
Ort: Steinfurt
292 Beiträge
 
Delphi XE2 Professional
 
#3

Re: 9 Variablen abgleichen / Keytasten festlegen

  Alt 18. Nov 2006, 17:49
Extrem "einfach", aber unelegant...

Delphi-Quellcode:
var
  v1, v2, v3, v4, v5, v6, v7, v8, v9: Integer;

  ...

  if ((v1 <> v2) and (v1 <> v3) and (v1 <> v4) and (v1 <> v5) and (v1 <> v6) and (v1 <> v7) and (v1 <> v8) and (v1 <> v9)) and
     ((v2 <> v3) and (v2 <> v4) and (v2 <> v5) and (v2 <> v6) and (v2 <> v7) and (v2 <> v8) and (v2 <> v9)) and
     ((v3 <> v4) and (v3 <> v5) and (v3 <> v6) and (v3 <> v7) and (v3 <> v8) and (v3 <> v9)) and
     ((v4 <> v5) and (v4 <> v6) and (v4 <> v7) and (v4 <> v8) and (v4 <> v9)) and
     ((v5 <> v6) and (v5 <> v7) and (v5 <> v8) and (v5 <> v9)) and
     ((v6 <> v7) and (v6 <> v8) and (v6 <> v9)) and
     ((v7 <> v8) and (v7 <> v9)) and
     (v8 <> v9) then
       ShowMessage('Alles ist irgendwie ungleich... glaube ich ;-)');
In meinen Augen die elegantere Variante...

Delphi-Quellcode:
var
  a: array[1..9] of Integer;
  i, n: Integer;
  AlleUnterschiedlich: Boolean;

  ...

  AlleUnterschiedlich := True;
  for i := 1 to 9 do
    for n := 1 to 9 do
      if (i <> n) and (a[i] = a[n]) then
      begin
        AlleUnterschiedlich := False;
        Break;
      end;
  if AlleUnterschiedlich then
    ShowMessage('Yoh!');
Debuggers don't remove Bugs, they only show them in Slow-Motion.
  Mit Zitat antworten Zitat