网易笔试 网易互娱前端 2020.04.11

唉不知道能不能过,求大佬给debug指导和测试用例
4道编程题实现出1,2题
第3题(忘了复制代码)牛客网python不知道为什么吞掉一个bug没任何报错,调试浪费太多时间凉凉
#9进制数字相加,通过75%
def add(num1 , num2):
        # write code here
        hasDot = False
        if '.' in num1&nbs***bsp;'.' in num2:
            hasDot = True
            
        n1 = num1.split('.')
        n2 = num2.split('.')
        

        if len(n1[0]) > len(n1[0]):
            n2[0] = (len(n1[0]) - len(n2[0])) * '0' + n2[0]
        else:
            n1[0] = (len(n2[0]) - len(n1[0])) * '0' + n1[0]
    
        if len(n1) == 1:
            n1.append('')
        if len(n2) == 1:
            n2.append('')
        if len(n1[1]) > len(n2[1]):
            n2[1] = n2[1] + (len(n1[1]) - len(n2[1])) * '0'
        else:
            n1[1] = n1[1] + (len(n2[1]) - len(n1[1])) * '0'
        
        num1 = n1[0] + n1[1]
        num2 = n2[0] + n2[1]

        dec = max(len(n1[1]), len(n2[1]))
        res = '' 
        carry = 0
        for i in range(len(num1) - 1, -1, -1):
            tmp = int(num1[i]) + int(num2[i]) + carry
            if tmp >= 9:
                carry = 1
                tmp -= 9
            else:
                carry = 0
            res = str(tmp) + res
        if carry:
            res = str(carry) + res
        #print(res)

        if hasDot:
            res = res[:-dec] + '.' + res[-dec:]
        #print(res)
        return res


add("123.25","44.15")
#工人分配方案数量,通过大概45%
#用memoization,但是怎么去掉重复方案啊?

import sys 
inputs = []
for l in sys.stdin:
    inputs.append(l)
ws = inputs[1].strip().split(' ')
js = inputs[2].strip().split(' ')

nums = {}
def memo(ws, js):
    #memoize 
    if tuple(ws) in nums:
        return nums[tuple(ws)]
    
    if len(ws) == 1:
        if ws[0] >= js[0]:
            return 1
        else:
            return 0

    #duplicate numbers -> factorial
    first = ws[0]
    dup = True
    for w in ws:
        if not w == first:
            dup = False
            break
    if dup:
        fac = 1
        for i in range(1, len(ws) + 1):
            fac *= i
        #memoize
        nums[tuple(ws)] = fac
        return fac
    
    total = 0

    #rotate
    for i in range(len(ws)):
        for j in range(1, len(ws)):
            l = memo(ws[:j],js[:j])
            r = memo(ws[j:],js[j:])
            total = max(total, l * r)
            #print(ws, js)
            #print(l, r, total)
        ws.append(ws.pop(0))

    #memoize 
    nums[tuple(ws)] = total
    #print(ws, total)
    return total
        

print(memo(ws, js) % int(inputs[3]))



#网易笔试##网易互娱#
全部评论
看我主页
2
送花
回复
分享
发布于 2020-04-12 00:16
后来有面试吗
1
送花
回复
分享
发布于 2020-04-24 10:23
秋招专场
校招火热招聘中
官网直投
工人那道,我用动态规划是过了60。第一道九进制的字符串操作得我晕了,只过了25。最后一道过了50。游戏职位的那道没做,太长了。提前半小时交卷了
点赞
送花
回复
分享
发布于 2020-04-11 21:45
工人那道是先排序,然后两个有序数组排序
点赞
送花
回复
分享
发布于 2020-04-11 21:48
为啥我的只有三道编程题,而且都不能用js编码。。。
点赞
送花
回复
分享
发布于 2020-04-12 08:18
你好,网易互娱前端是web前端吗?还是游戏前端?
点赞
送花
回复
分享
发布于 2020-05-08 19:49

相关推荐

点赞 评论 收藏
转发
1 5 评论
分享
牛客网
牛客企业服务