题解 | #配置文件恢复#

配置文件恢复

http://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5

def match_command(str):
    s = str.split()
    if len(s) == 1:
        if s[0][0] == single_c[0] and s[0] in single_c:
            return 'reset what'
        else:
            return 'unknown command'

    elif len(s) == 2:
        index1 = []
        index2 = []
        for i in range(len(c)):
            if s[0][0] == c[i][0][0] and s[0] in c[i][0]:
                index1.append(i)
            else:
                continue
        if not index1:
            return 'unknown command'
        for j in range(len(c)):
            if s[1][0] == c[j][1][0] and s[1] in c[j][1]:
                index2.append(j)
            else:
                continue
        res = [i for i in index1 if i in index2]
        if len(res) != 1:
            return 'unknown command'
        else:
            return ''.join(r[res[0]])

while 1:
    try:
        single_c = 'reset'
        c = [['reset', 'board'], ['board', 'add'], ['board', 'delete'], ['reboot', 'backplane'], ['backplane', 'abort']]
        r = ['board fault', 'where to add', 'no board at all', 'impossible', 'install first']
        s = input()
        print(match_command(s))
    except:
        break
全部评论

相关推荐

面试摇了我吧:啊哈哈面试提前五个小时发,点击不能参加就是放弃
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务