首页 > 网易互娱 9.5游戏开发笔试
头像
芒果爱泡泡
编辑于 2020-09-05 17:40
+ 关注

网易互娱 9.5游戏开发笔试 投票

以为三道题150分钟绰绰有余,结果第一道题做了一个半小时。


第一题:
n,m=map(int,input().split())
nums=list(map(int,input().split()))
ans=[[0] for _ in range(len(nums)+1)]
for i in range(len(nums)):
    ans[i+1][0]=nums[i]
    
for _ in range(m):
    path,res=[],[]
    k=int(input())
    for _ in range(k):
        path=list(input().split())
        res.append(path)
    curleft,curright,sum_=[],[],0
    for i in range(len(res)):
        if res[i][0]=='left':
                if res[i][1]=='take':
                    if len(ans[int(res[i][2])])!=1:
                        curleft.append(ans[int(res[i][2])].pop())
                    else:
                        curleft.append(ans[int(res[i][2])][0])
                elif res[i][1]=='return':
                    ans[int(res[i][2])].append(curleft.pop())
                elif res[i][1]=='keep':
                    sum_+=curleft.pop()
        elif res[i][0]=='right':
                if res[i][1]=='take':
                    if len(ans[int(res[i][2])])!=1:
                        curright.append(ans[int(res[i][2])].pop())
                    else:
                        curright.append(ans[int(res[i][2])][0])
                elif res[i][1]=='return':
                    ans[int(res[i][2])].append(curright.pop())
                elif res[i][1]=='keep':
                    sum_+=curright.pop()

    if len(curleft)==1:
        sum_+=curleft.pop()
    if len(curright)==1:
        sum_+=curright.pop()
    print(sum_)


全部评论

(4) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐