有一个按位数从小到大排序的数,
最短为4位,
最长为10位,
每位最小为0,
每位最大为9
这组数中不能有任意两位数相同,
最小且最短为:
0123
最长且最大为:
0123456789求一:
在这个数中任选三位组成一个3位数,
这个3位数中的任意两位必须相同,
但是3位不能同时为某数,
不允许如:111 222 333 444 这样并把这个3位数的每位从小到大排序,
如:
233 232 332都看成是233
找出能组成多少个3位数?
谢谢!!求二:
在这个数中任选三位组成一个3位数,
这个3位数中不能有任意两位数相同,
3位都相同更是不可以,
不允许如:122 222 322 432 这样
并把这个3位数每位从小到大排序:
如:
123 321 231 132 123 都看成是:123找出能组成多少个3位数?我今天发了两贴,
请各位朋友帮忙完成.谢谢啦

解决方案 »

  1.   

    补充一下,所有数均用String或array of string[1]存储
    字符处理
      

  2.   

    http://community.csdn.net/Expert/topic/3788/3788733.xml?temp=.738949
      

  3.   

    问题很简单,但描述起来可能比较麻烦。求解1的函数:GetAllNumber1()
    求解2的函数:GetAllNumber2()源程序:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Memo1: TMemo;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;  function GetAllNumber1(const S: string): string;
      function GetAllNumber2(const S: string): string;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      Memo1.Text := GetAllNumber1('0123456789');
    end;function GetAllNumber1(const S: string): string;
    var
      i, j, k: Integer;
      A: string;
    begin
      Result := '';
      for i:=1 to Length(S) do
        for j:=1 to Length(S) do
          for k:=1 to Length(S) do
            if (S[i] = S[j]) and (S[k] > S[j]) or
               (S[j] = S[k]) and (S[k] > S[i]) then
              Result := Result + S[i] + S[j] + S[k] + #13#10;
    end;function GetAllNumber2(const S: string): string;
    var
      i, j, k: Integer;
      A: string;
    begin
      Result := '';
      for i:=1 to Length(S) do
        for j:=1 to Length(S) do
          for k:=1 to Length(S) do
            if (S[j] > S[i]) and (S[k] > S[j]) then
              Result := Result + S[i] + S[j] + S[k] + #13#10;
    end;end.
      

  4.   

    TO DDGG(叮叮当当) 就是这个意思
    可是这样运行太慢
      

  5.   

    var
    a:array[0..9] of byte;
    Len:Integer;
    i:integer;
    j:integer;
    k:integer;
    l,m,n:integer;
    s:string;
    begin
      s:='0123456789';
      Memo1.Clear;
      Memo2.Clear;
      Len:=Length(s);
      l:=0;
      m:=0;
      n:=0;
      ZeroMemory(Pointer(@a),10);
      for i:=1 to Len do
      begin
         inc(a[StrToInt(s[i])]);
      end;
      for i:=0 to 9 do
      begin
         inc(l);
         if (a[i]>1)  then
         begin
            if i<>0 then
               for j:=0 to i-1 do
               begin
                  inc(m);
                  if a[j]<>0 then Memo1.Lines.Add(Format('%d%d%d',[j,i,i]));
               end;
            if (i<>9) then
            for j:=i+1 to 9 do
            begin
               inc(n);
               if a[j]<>0 then
                  Memo1.Lines.Add(Format('%d%d%d',[i,i,j]));
            end;
         end;
      end;
      memo1.Lines.Add(Format('l=%d,m=%d,n=%d',[l,m,n]));
      l:=0;
      m:=0;
      for i:=0 to 9 do
      begin
         inc(l);
         if a[i]<>0 then
         for j:=i+1 to 9 do
         begin
            inc(m);
            if a[j]<>0 then
               for k:=j+1 to 9 do
               begin
                  inc(n);
                  if a[k]<>0 then Memo2.Lines.Add(Format('%d%d%d',[i,j,k]));
               end;
         end;
      end;
      memo2.Lines.Add(Format('l=%d,m:=%d,n:=%d',[l,m,n]));
    end;
      

  6.   

    //参考http://community.csdn.net/Expert/topic/3660/3660145.xml?temp=.1523859
    //《寻求最快的算法!!!! 》一贴当中QuickKeyBoard() 提出来的Hash散列表
    //从而实现了其一是排序,其二是计数
    //即当一个数,例如当0在字串当中未出现则a[0]=0,
    //而1出现一次则a[1]=1,2出现两次a[2]=2...
    //问题一当中我们就需要的是a[index]>1的数以做组合成员数,类似于ijj或jii
    //问题二当中我们将刚好把这10个数当中不为0的数做一个组合var
       a:array[0..9] of byte; //定义一个Hash散列表空间
       i:integer;
       j:integer;
       k:integer;
       l,m,n:integer;         //复杂度计数器
       s:string;              //数字串
    begin
       s:='0123456789';        //显式初始化   Memo1.Clear;            //初始化显示区域
       Memo2.Clear;   l:=0;    //初始化计数器
       m:=0;
       n:=0;   ZeroMemory(Pointer(@a),10); //初始化Hash散列表空间   for i:=1 to Length(s) do
          inc(a[StrToInt(s[i])]); //置入Hash表  //问题一
      for i:=0 to 9 do
      begin
         inc(l);
         if (a[i]>1)  then  //iij或jii
         begin        if i<>0 then    //该数字存在于数串当中
               for j:=0 to i-1 do //做jii组合
               begin
                  inc(m);
                  if a[j]<>0 then
                     Memo1.Lines.Add(Format('%d%d%d',[j,i,i]));
               end;        for j:=i+1 to 9 do //做iij组合
            begin
               inc(n);
               if a[j]<>0 then
                  Memo1.Lines.Add(Format('%d%d%d',[i,i,j]));
            end;
         end;
      end;  memo1.Lines.Add(Format('l=%d,m=%d,n=%d',[l,m,n]));  //问题二
      l:=0;    //初始化计数器
      m:=0;
      n:=0;  for i:=0 to 9 do
      begin
         inc(l);
         if a[i]<>0 then //该数字存在于数串当中
            for j:=i+1 to 9 do
            begin
               inc(m);
               if a[j]<>0 then
                  for k:=j+1 to 9 do
                  begin
                     inc(n);
                     if a[k]<>0 then
                        Memo2.Lines.Add(Format('%d%d%d',[i,j,k]));
                  end;
            end;
      end;
      memo2.Lines.Add(Format('l=%d,m:=%d,n:=%d',[l,m,n]));
    end;
      

  7.   

    哦,用HASH来判断是个聪明的做法,但是程序的主要开销仍然会耗在循环选取字符串上。http://community.csdn.net/Expert/TopicView.asp?id=3843824