题解 | 斗兽棋
斗兽棋
https://www.nowcoder.com/practice/0b5afb815f6848d9a7f9c1b0ce514b95
import sys
# for line in sys.stdin:
# a = line.split()
# print(int(a[0]) + int(a[1]))
# s = input().split()
# def trans(x):
# num = 0
# if x == 'elephant':
# num = 4
# if x == 'tiger':
# num = 3
# if x == 'cat':
# num = 2
# if x == 'mouse':
# num = 1
# return num
# s = [trans(x) for x in s]
# if s[0] == 4 and s[1] ==1 :
# print('lose')
# elif s[0] == 1 and s[1] ==4:
# print('win')
# elif s[0] == s[1]+1:
# print('win')
# elif s[0]==s[1]-1:
# print('lose')
# else:
# print('tie')
# 这是个字典类型的
rules = {"elephant": "tiger", "tiger": "cat", "cat": "mouse", "mouse": "elephant"}
s1, s2 = map(str, input().strip().split())
if rules[s1] == s2: #字典类型,如果s1是elephant则返回的是tiger
print("win")
elif rules[s2] == s1:
print("lose")
else:
print("tie")
唯一需要注意的就是 必须两者相邻,才会有输赢,越级是平手

查看13道真题和解析