其他分享
首页 > 其他分享> > 校招笔试题集锦(持续更新)

校招笔试题集锦(持续更新)

作者:互联网

华为

1、修改机票

 

代码:

import sys
def reschedule(origins, changes):
    tickets = {}
    new_tickets = {}
    for origin in origins:
        airline, seat, name = origin.split(',')
        tickets[(airline, seat)] = name
        new_tickets[name] = (airline, seat)

    for change in changes:
        old_airline, old_seat, new_airline, new_seat = change.split(',')
        name2 = tickets[(old_airline, old_seat)]
        new_tickets.pop(name2)
        new_tickets[name2] = (new_airline, new_seat)
    print(new_tickets)

if __name__=="__main__":
    # input=
    '''
    3
    CZ7132,A1,ZHANGSAW
    CZ7132,A2,ZHAOSI
    CZ7156,A2,WANGWU
    2
    CZ7132,A1,CZ7156,A2
    CZ7156,A2,CZ7156,A3
    '''

    N = int(sys.stdin.readline().strip('\n'))
    origins = []
    changes = []
    for i in range(N):
        origins.append(sys.stdin.readline().strip('\n'))

    M = int(sys.stdin.readline().strip('\n'))
    for j in range(M):
        changes.append(sys.stdin.readline().strip('\n'))

    # origins = ['CZ7132,A1,ZHANGSAW', 'CZ7132,A2,ZHAOSI', 'CZ7156,A2,WANGWU']
    # changes = ['CZ7132,A1,CZ7156,A2', 'CZ7156,A2,CZ7156,A3']
    if not 0 <= N <= 100:
        print("The number of the tickets is error!")
    elif not 0 <= M <= N:
        print("The number of the revised tickets is error!")
    else:
        reschedule(origins, changes)

 

标签:tickets,笔试,seat,A2,airline,集锦,new,校招,CZ7156
来源: https://blog.csdn.net/hitzijiyingcai/article/details/100864658