function cBoxCheck(a, b, c, d, e, f, g, h, i, j: Boolean): Integer;
var
  x: Integer;
begin
  x:= 0;
  if a then x:= x + 1;
  if b then x:= x + 5;
  if c then x:= x + 9;
  if d then x:= x + 13;
  if e then x:= x + 17;
  if f then x:= x + 21;
  if g then x:= x + 25;
  if h then x:= x + 29;
  if i then x:= x + 33;
  if j then x:= x + 37;
  result:= x;
end;怎么从返回的结果里得知具体是由哪几个数相加得来的,求求大侠帮帮忙。

解决方案 »

  1.   

    单单以一个结果回推回去,不可能吧,比如结果是10,那到底是9+1,还是5+5,还是1+9既然是根据a, b, c, d ...选择公式,不可以再利用它吗?
      

  2.   

    逆出来可能多个结果,比如
    b、d为true,其他为false,result = 18
    a、e为true,其他为false, result 也 = 18
      

  3.   

    如果再过给几个不同的数,就很有可能对撞出a..j,毕竟a..j也就1024种组合
      

  4.   


    就楼主的代码来说,结果为10只可能a、c为true,其他false。不过其他的结果未必能逆推出唯一的组合,象7楼举的反例。
      

  5.   

    真不好意思各位,24小时以后我撤销这个帖子,所以不要再回了。抱歉一上来是我把这个想复杂了,想学习的我把我的思路和这部分的源码给大家,不要喷我,其实很简单
    function cBoxCheck(a, b, c, d, e, f, g, h, i, j: Boolean): String;
    var
      x: String;
    begin
      x:= '';
      if a then x:= x + '0';
      if b then x:= x + '1';
      if c then x:= x + '2';
      if d then x:= x + '3';
      if e then x:= x + '4';
      if f then x:= x + '5';
      if g then x:= x + '6';
      if h then x:= x + '7';
      if i then x:= x + '8';
      if j then x:= x + '9';
      result:= x;
    end;uses StrUtils;
    procedure TFrmFind.cBoxSet(x: String; a, b, c, d, e, f, g, h, i, j: TCheckBox);
    begin
      if AnsiContainsStr(x, '0') then a.Checked:= True;
      if AnsiContainsStr(x, '1') then b.Checked:= True;
      if AnsiContainsStr(x, '2') then c.Checked:= True;
      if AnsiContainsStr(x, '3') then d.Checked:= True;
      if AnsiContainsStr(x, '4') then e.Checked:= True;
      if AnsiContainsStr(x, '5') then f.Checked:= True;
      if AnsiContainsStr(x, '6') then g.Checked:= True;
      if AnsiContainsStr(x, '7') then h.Checked:= True;
      if AnsiContainsStr(x, '8') then i.Checked:= True;
      if AnsiContainsStr(x, '9') then j.Checked:= True;
    end;
      

  6.   

    不对吧。
    比如 f为true,其他false,此时x=21,按照cBoxSet推出来的则是b、c为true,其他false,能对吗?:)