2018刑侦推理 java_如何看待2018年刑侦科推理试题?

python初学者一枚,交流一下经验

代码如下:option = ['A','B','C','D'] #定义选项

lst = []

for x1 in option:

for x2 in option:

for x3 in option:

for x4 in option:

for x5 in option:

for x6 in option:

for x7 in option:

for x8 in option:

for x9 in option:

for x10 in option:

lst1 = ['n',x1,x2,x3,x4,x5,x6,x7,x8,x9,x10] #使用‘n’来占位

lst.append(lst1) #得到所有可能答案集合

for a in lst: #遍历答案,第一题没有条件限制

if (a[2]== 'A' and a[5] == 'C') or (a[2] == 'B' and a[5] == 'D') or \

(a[2] == 'C' and a[5] == 'A') or (a[2] == 'D' and a[5] == 'B'): #第二题条件

if (a[3] == 'A' and (a[2] =a= a[6] == a[4]) and (a[3] != a[6])) or \

(a[3] == 'B' and (a[2] == a[3] == a[4]) and (a[6] != a[3])) or \

(a[3] == 'C' and (a[3] == a[6] == a[4]) and (a[2] != a[3])) or \

(a[3] == 'D' and (a[3] == a[6] == a[2]) and (a[4] != a[3])): #第三题条件

if ((a[4] == 'A' and a[1] == a[5])) or ((a[4] == 'B' and a[2] == a[7])) or \

((a[4] == 'C' and a[1] == a[9])) or (a[4] == 'D' and (a[6] == a[10])): #第四题条件

if (a[5] == 'A' and a[5] == a[8]) or (a[5] == 'B' and a[5] == a[4]) or\

(a[5] == 'C' and a[5] == a[9]) or (a[5] == 'D' and a[5] == a[7]): #第五题条件

if (a[6] == 'A' and a[8] == a[2] == a[4]) or (a[6] == 'B' and a[8] == a[1] == a[6]) or \

(a[6] == 'C' and a[8] == a[3] == a[10]) or (a[6] == 'D' and a[8] == a[5] == a[9]): #第六题条件

if (a[8]=='A' and (option.index(a[7]) - option.index(a[1])) != 1 ) or\

(a[8]=='B' and (option.index(a[5]) - option.index(a[1])) != 1 ) or \

(a[8]=='C' and (option.index(a[2]) - option.index(a[1])) != 1 ) or \

(a[8]=='D' and (option.index(a[10]) - option.index(a[1])) != 1 ): #第八题条件

if (a[9] == 'A' and ((a[1] == a[6]) != (a[5] == a[6]))) or \

(a[9] == 'B' and ((a[1] == a[6]) != (a[5] == a[10])))or \

(a[9] == 'C' and ((a[1] == a[6]) != (a[5] == a[2])))or \

(a[9] == 'D' and ((a[1] == a[6]) != (a[5] == a[9]))): #第九题条件

number = [] #第七题、第十题

for i in option:

number.append(a.count(i))

difference = max(number) - min(number) #定义最小值、差值

if (a[7] == 'A' and option[number.index(min(number))] == 'C')or \

(a[7] == 'B' and option[number.index(min(number))] == 'B') or \

(a[7] == 'C' and option[number.index(min(number))] == 'A') or \

(a[7] == 'D' and option[number.index(min(number))] == 'D') : #第七题条件

if (a[10] == 'A' and difference == 3) or (a[10] == 'B' and difference == 2) or \

(a[10] == 'C' and difference == 4) or (a[10] == 'D' and difference == 1): #第十题条件

print(a[1:])

print('finished!')

运行结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值