2020字节跳动游戏提前批招聘笔试编程题

趣题分享

Gardon的18岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达18岁生日时所经过的天数都是一样的呢?似乎并不全都是这样,所以他想请你帮忙计算一下他和他的几个朋友从出生到达18岁生日所经过的总天数,让他好来比较一下。

思路

  • 分闰年输出,注意2-29直接判-1 不然会卡样例

Code

python

def func(year, month, day):
    yearmod=year%4
    if yearmod==0 and month==2 and day==29:
        return -1
    if yearmod==0 and month>=3:
        return 6573
    if yearmod==0 and month<=2 and day!=29:
        return 6574
    if yearmod==3 and month>=3:
        return 6575
    if yearmod==3 and month<=2:
        return 6574
    if yearmod<=2 and yearmod>=1:
        return 6574
T=int(input())
print(T)
input_store=[input() for _ in range(T)]
for str in input_store:
    year,month,day=map(int,str.split("-"))
    print(year,month,day)
    print(func(year,month,day))

判断包含通配符的匹配字符串是否完全匹配输入的字符串,匹配字符串中包含的通配符仅有" “和”?",且通配符不会连续出现。(要求完全匹配,而不是包含)其中,通配符“”代替 0
个或多个字符,通配符“.”代替一个字符

思路

  • 按序比较即可

Code

python

s = input()
p = input()
ind1, ind2 = 0, 0
n1, n2 = len(s), len(p)
chtmp = "."
res = False
breaksig = False

while (ind1 < n1) and (ind2 < n2):
    print(s[ind1:] + "    "+ p[ind2:])
    if s[ind1] == p[ind2]:
        if ind2 < n2 - 1 and p[ind2 + 1] == "*":
            ind1 += 1
        else:
            ind1 += 1
            ind2 += 1
    else:
        if p[ind2] == ".":
            if (ind2==n2-1) or (ind2 < n2 - 1 and p[ind2 + 1] != "*"):
                ind1 += 1
                ind2 += 1
            if ind2 < n2 - 1 and p[ind2 + 1] == "*":
                while (ind1 < n1 - 1 and s[ind1] == s[ind1 + 1]):
                    ind1 += 1
                ind2 += 2
        else:
            if ind2 < n2 - 1 and p[ind2 + 1] == "*":
                ind2 += 2
            else:
                breaksig = True

if breaksig == False and ind1 >= n1:
    while (ind2 < n2):
        if ind2 < n2 - 1 and p[ind2 + 1] == "*":
            ind2 += 2
        else:
            if p[ind2] == ".":
                ind2 += 1
            else:
                break
    if ind2 >= n2:
        res = True
if res:
    print("true")
else:
    print("false")

商品价格只有150,200,350,不找零,给定一个n,能买到最大的货物价值是多少

思路

  • 按序比较即可

Code

python


T=int(input())
T_data=[int(input()) for _ in range(T)]
for n in T_data:
    dp=[0]*(n+1)
    for i in range(1,n+1):
        if i>=150:
            dp[i] = max(dp[i],dp[i-150]+150)
        if i>=200:
            dp[i] = max(dp[i],dp[i-200]+200)
        if i>=350:
            dp[i] = max(dp[i],dp[i-350]+350)
    print(n-dp[n])

你可能感兴趣的:(互联网)