牛客华为机试HJ66
作者:互联网
1. 问题描述
2. Solution
import re
import sys
if sys.platform != "linux":
file_in = open("input/HJ66.txt")
sys.stdin = file_in
command_map = {
# ("reset", ""): "reset what",
("reset", "board"): "board fault",
("board", "add"): "where to add",
("board", "delete"): "no board at all",
("reboot", "backplane"): "impossible",
("backplane", "abort"): "install first"
}
"""
r b
b a
bo a
reb
r
res
unknown command
unknown command
where to add
unknown command
reset what
reset what
"""
def solve(s):
parts = s.split()
matched_keys = []
if len(parts) == 1:
if "reset".startswith(s):
print("reset what")
else:
print("unknown command")
return
for k, v in command_map.items():
p1, p2 = parts
if k[0].startswith(p1) and k[1].startswith(p2):
matched_keys.append(k)
if not matched_keys or len(matched_keys) > 1:
print("unknown command")
return
print(command_map[matched_keys[0]])
for line in sys.stdin:
s = line.strip()
solve(s)
标签:reset,keys,unknown,牛客,HJ66,command,board,机试,matched 来源: https://www.cnblogs.com/junstat/p/16172597.html