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

华为

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)

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

上一篇:HDU 1260 Tickets


下一篇:多线程抢票系统浅析