logo逻辑判断有A、B、C、D、E五人参加考试,他们在一起猜测名次:A猜E第一,B猜自己第二,C猜A第五(最差),D猜

1个回答

  • TO A :A

    IF :A > 5 STOP

    B 1

    A :A + 1

    END

    TO B :B

    IF :B > 5 STOP

    IF NOT :B = :A [C 1]

    B :B + 1

    END

    TO C :C

    IF :C > 5 STOP

    IF AND (NOT :C = :A) (NOT :B = :C) [D 1]

    C :C + 1

    END

    TO D :D

    IF :D > 5 STOP

    IF (AND (NOT :A = :D) (NOT :B = :D) (NOT :C = :D)) [E 15 - :A - :B - :C - :D]

    D :D + 1

    END

    TO E :E

    MAKE "T1 0 MAKE "T2 0

    IF AND :A = 1 :E = 1 [MAKE "T1 :T1 + 1]

    IF AND :B = 1 :B = 2 [MAKE "T1 :T1 + 1]

    IF AND :C = 1 :A = 5 [MAKE "T1 :T1 + 1]

    IF AND :D = 1 (NOT :C = 1) [MAKE "T1 :T1 + 1]

    IF AND :E = 1 :D = 1 [MAKE "T1 :T1 + 1]

    IF AND :A = 2 :E = 1 [MAKE "T2 :T2 + 1]

    IF AND :B = 2 :B = 2 [MAKE "T2 :T2 + 1]

    IF AND :C = 2 :A = 5 [MAKE "T2 :T2 + 1]

    IF AND :D = 2 (NOT :C = 1) [MAKE "T2 :T2 + 1]

    IF AND :E = 2 :D = 1 [MAKE "T2 :T2 + 1]

    IF AND :T1 = 1 :T2 = 1 [(PR :A :B :C :D :E)]

    END