回 帖 发 新 帖 刷新版面

主题:关于三人对比赛名次进行预测问题!!

甲说:"A得第一,B得第三"乙说:"C得第一,D得第四"丙说:"D得第一,B得第三"每人说对一半,请按A到D排列啊!

回复列表 (共1个回复)

沙发

这用脑袋推敲一下就能拿到结果了
但非得用QB的时候......
就套用我的字符排列吧

a$ = "ABCD"                                '顺序排列好,为最小值
l = LEN(a$)

DO
  R1=0
  R2=0
  R3=0

  if instr(a$,"A")=1 then R1=R1+1           '甲说的话
  if instr(a$,"B")=3 then R1=R1+1

  if instr(a$,"C")=1 then R2=R2+1           '乙说的话
  if instr(a$,"D")=4 then R2=R2+1

  if instr(a$,"D")=1 then R3=R3+1           '丙说的话
  if instr(a$,"B")=3 then R3=R3+1

  if R1=1 and R2=1 and R3=1 then print a$   '每人说对一半

  GOSUB 10
LOOP


10                                              '找下一个排列方式
for e=(l-1) to 1 step -1                        '找不合适的位置 e
  if mid$(a$,e,1)<mid$(a$,e+1,1) then exit for
next
if e<1 then end

FOR i = l TO (e + 1) STEP -1                    '找需要交换的位置 i
    IF MID$(a$, i, 1) > MID$(a$, e, 1) THEN EXIT FOR
NEXT
  b$ = MID$(a$, i, 1)                           '交换字符
  MID$(a$, i, 1) = MID$(a$, e, 1)
  MID$(a$, e, 1) = b$

FOR i = (e + 1) TO (l + e + 1) \ 2              '对后面段的字符排顺序
    j = l + e + 1 - i
    b$ = MID$(a$, i, 1)
    MID$(a$, i, 1) = MID$(a$, j, 1)
    MID$(a$, j, 1) = b$
NEXT
RETURN

我来回复

您尚未登录,请登录后再回复。点此登录或注册