卡码网京东模拟笔试(2023京东真题)

1.题目描述:卡码网132. 夹吃棋

在一个 3 * 3 的棋盘上,小红和小紫正在玩“夹吃棋”。 所谓“夹吃棋”,即如果存在一个白子,它的两侧 (横向或者纵向)相邻都是黑子,则这个棋子将被“夹吃”,对于黑棋亦然。 

如果一个棋盘的局面没有一方被夹吃,或者黑白双方都被对面夹吃,则认为是平局。如果只有一方夹吃了另一方,则认为夹吃方赢,被夹吃方输。 

小红执黑棋,小紫执白棋,现在给定一个局面,请你判断当前棋局是谁获胜。

解决:

n = int(input().split()[0])
data = []
dictt = ['o*o','*o*']

for tcase in range(n):
    qipan = []
    red = 0
    purple = 0
    for i in range(3):
        strs = input().strip().split()[0]
        if strs in dictt:
            if strs == dictt[0]:
                purple += 1
            if strs == dictt[1]:
                red += 1
        qipan.append(strs)
    for i in range(3):
        strs_t = ''
        for j in range(3):
            strs_t += qipan[j][i]
        if strs_t in dictt:
            if strs_t == dictt[0]:
                purple += 1
            if strs_t == dictt[1]:
                red += 1
    if red>0 and purple==0:print('kou')
    if red==0 and purple>0:print('yukan')
    if (red>0 and purple>0) or (red==0 and purple==0):print('draw')
    

2.题目描述:卡码网 133.小红买药 133. 小红买药 (kamacoder.com)

小红准备买药治病。已知共有 n 种症状和 m 种药,第 i 种药可以治疗一些症状,但可能会导致一些副作用,添加一些新的症状。小红依次服用了一些药,请你告诉小红,当她每次服用一副药时,当前还有多少症状?

n = int(input().strip().split()[0])
start = list(map(int,input().strip().split()[0]))
m = int(input().strip().split()[0])
data = []
for tcase in range(m):
    medichine = []
    zhiliao = list(map(int,input().strip().split()[0]))
    l_zhiliao = list(map(int,input().strip().split()[0]))
    medichine.append(zhiliao)
    medichine.append(l_zhiliao)
    data.append(medichine)
q = int(input().strip().split()[0])
for i in range(q):
    n_yao = int(input().strip().split()[0])
    zhiliao,zhiliao_l = data[n_yao-1][0],data[n_yao-1][1]
    for i in range(len(start)):
        if start[i] == 1 and zhiliao[i] == 1:
            start[i] = 0
        if start[i] == 0 and zhiliao_l[i] ==1:
            start[i] = 1
    print(start.count(1))

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值