从0123456789中组合成号码:
000,001,002,,,009,012,013,,,019,,,999注意是组合,内部不排序,001,010,100为同一号码,同理012,021,102,120,201,210为号码.
共有220个号码.
000 001 002 003 004 005 006 007 008 009 011 012 013 014 015 016 017 018 019 022 023 024 025 026 027 028 029 033 034 035 036 037 038 039 040 045 046 047 048 049 055 056 057 058 059 066 067 068 069 077 078 079 088 089 099 111 112 113 114 115 116 117 118 119 122 123 124 125 126 127 128 129 133 134 135 136 137 138 139 144 145 146 147 148 149 155 156 157 158 159 166 167 168 169 177 178 179 188 189 199 222 223 224 225 226 227 228 229 233 234 235 236 237 238 239 244 245 246 247 248 249 255 256 257 258 259 266 267 268 269 277 278 279 288 289 299 333 334 335 336 337 338 339 344 345 346 347 348 349 355 356 357 358 359 366 367 368 369 377 378 379 388 389 399 444 445 446 447 448 449 455 456 457 458 459 466 467 468 469 477 478 479 488 489 499 555 556 557 558 559 566 567 568 569 577 578 579 588 589 599 666 667 668 669 677 678 679 688 689 699 777 778 779 788 789 799 888 889 899 999 

解决方案 »

  1.   


    function StrInList(str:string;strs:TStrings):boolean;
    begin
        Result:=(strs.IndexOf(str[1]+str[2]+str[3])>=0)
                or (strs.IndexOf(str[1]+str[3]+str[2])>=0)
                or (strs.IndexOf(str[2]+str[1]+str[3])>=0)
                or (strs.IndexOf(str[2]+str[3]+str[1])>=0)
                or (strs.IndexOf(str[3]+str[1]+str[2])>=0)
                or (strs.IndexOf(str[3]+str[2]+str[1])>=0);
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
        i,j,k:integer;
        strs:TStrings;
    begin
        strs:=TStringList.Create;
        for i:=0 to 9 do
            for j:=0 to 9 do
                for k:=0 to 9 do
                begin
                    if not StrInList(IntToStr(i)+IntToStr(j)+IntToStr(k),strs) then
                        strs.Add(IntToStr(i)+IntToStr(j)+IntToStr(k));
                end;
        Memo1.Lines.Assign(strs);
        strs.Free;
    end;
      

  2.   

    三个数字乘以一个权码进行相加,剩以权码的目的是错开可能导致的重复,使得1*X+1*X+1*X <> 0*X+1*X+2*X(这里的X不是一个定值,而是各数字对应的Hash码)然后找一个可行的Hash算法就可以解决了。
      

  3.   

    如果你只是为了代码来的话,建议你到http://prj.csdn.net
      

  4.   

    uses
      Math;
    type
      MyRecord = record
        Value: String;
        Hash: Integer;
      end;procedure QuickSort(var HashArray: Array of MyRecord; L, R: Integer);
    var
      I, J: Integer;
      P, T: MyRecord;
    begin
      repeat
        I := L;
        J := R;
        P := HashArray[(L + R) shr 1];
        repeat
          //while SCompare(SortList^[I], P) < 0 do
          while HashArray[I].Hash < P.Hash do        Inc(I);
          while HashArray[J].Hash > P.Hash do
            Dec(J);
          if I <= J then
          begin
            T := HashArray[I];
            HashArray[I] := HashArray[J];
            HashArray[J] := T;
            Inc(I);
            Dec(J);
          end;
        until I > J;
        if L < J then
          QuickSort(HashArray, L, J);
        L := I;
      until I >= R;
    end;
    function GetHash(Value:String): Integer;
    var
      I: Integer;
    begin
      Result := 0;
      for I := 1 to Length(Value) do
        begin
          Result := Result + Trunc(IntPower(4, Ord(Value[I])- Ord('0')));
        end;
    end;procedure Test;
    var
      str_Test, str_Temp: AnsiString;
      tls, tls_Group: TStringList;
      HashArray: Array of MyRecord;
      I,HashValue, Index: Integer;
    begin
      str_Test := '000 001 002 003 004 005 006 007 008 009 011 012 013 014 015 016 ';
      str_Test := str_Test + '017 018 019 022 023 024 025 026 027 028 029 010 100 ';
      str_Test := str_Test + '033 034 035 036 037 038 039 040 045 046 047 048 049 ';
      str_Test := str_Test + '055 056 057 058 059 066 067 068 069 077 078 079 088 ';
      str_Test := str_Test + '089 099 111 112 113 114 115 116 117 118 119 122 123 ';
      str_Test := str_Test + '124 125 126 127 128 129 133 134 135 136 137 138 139 ';
      str_Test := str_Test + '144 145 146 147 148 149 155 156 157 158 159 166 167 ';
      str_Test := str_Test + '168 169 177 178 179 188 189 199 222 223 224 225 226 ';
      str_Test := str_Test + '227 228 229 233 234 235 236 237 238 239 244 245 246 ';
      str_Test := str_Test + '247 248 249 255 256 257 258 259 266 267 268 269 277 ';
      str_Test := str_Test + '278 279 288 289 299 333 334 335 336 337 338 339 344 ';
      str_Test := str_Test + '345 346 347 348 349 355 356 357 358 359 366 367 368 ';
      str_Test := str_Test + '369 377 378 379 388 389 399 444 445 446 447 448 449 ';
      str_Test := str_Test + '455 456 457 458 459 466 467 468 469 477 478 479 488 ';
      str_Test := str_Test + '489 499 555 556 557 558 559 566 567 568 569 577 578 ';
      str_Test := str_Test + '579 588 589 599 666 667 668 669 677 678 679 688 689 ';
      str_Test := str_Test + '699 777 778 779 788 789 799 888 889 899 999';
      tls := TStringList.Create;
      try
        tls.Text := StringReplace(str_Test,' ',#13#10,[rfReplaceAll]);
        SetLength(HashArray, tls.Count);
        try
          for I := 0 to tls.Count - 1 do
            begin
              HashArray[i].Value := tls.Strings[i];
              HashArray[I].Hash := GetHash(HashArray[i].Value);
            end;
          QuickSort(HashArray,0, Length(HashArray) - 1);
          tls_Group := tls;
          tls_Group.Clear;
          HashValue := -1;
          Index := 0;
          str_Temp := '';
          for I := 0 to Length(HashArray) - 1 do
            begin
              if HashArray[i].Hash <> HashValue then
                begin
                  if str_Temp <> '' then
                    tls_Group.Add(str_Temp);
                  Inc(Index);
                  HashValue := HashArray[i].Hash;
                  str_Temp := '第' + IntToStr(Index) + '组:'+ HashArray[I].Value + ' ';
                end
              else
                begin
                  str_Temp := str_Temp + HashArray[I].Value + ' ';
                end;
            end;
          if str_Temp <> '' then
            tls_Group.Add(str_Temp);
          ShowMessage(tls_Group.Text);
        finally
          SetLength(HashArray, 0);
          HashArray := Nil;
        end;
      finally
        tls.Free;
      end;
    end;