由于在参加大疆的考试,所以完成了大疆的考试,8.20进入了考场,少了一个多小时。
网易游戏的题目还算简单。
第一题
缴税问题,小于5000元不交税,否则(工资-5000)为需要缴税的部分,然后分批次计算缴税费用。
import sys
n = int(sys.stdin.readline().strip())
for i in range(n):
v = int(sys.stdin.readline().strip())
m = 0
if v <= 5000:
print(str(m))
else:
v = v - 5000
if v <= 3000:
m += v * 0.03
elif v > 3000 and v <= 12000:
m += (3000*0.03 + (v-3000)*0.1)
elif v > 12000 and v <= 25000:
m += (3000*0.03 + (12000-3000)*0.1 + (v-12000)*0.2)
elif v > 25000 and v <= 35000:
m += (3000*0.03 + (12000-3000)*0.1 + (25000-12000)*0.2 + (v-25000)*0.25)
elif v > 35000 and v <= 55000:
m += (3000*0.03 + (12000-3000)*0.1 + (25000-12000)*0.2
+ (35000-25000)*0.25 + (v-35000)*0.3)
elif v > 55000 and v <= 80000:
m += (3000*0.03 + (12000-3000)*0.1 + (25000-12000)*0.2
+ (35000-25000)*0.25 + (55000-35000)*0.3 + (v-55000)*0.35)
else:
m += (3000*0.03 + (12000-3000)*0.1 + (25000-12000)*0.2
+ (35000-25000)*0.25 + (55000-35000)*0.3 + (80000-55000)*0.35
+ (v-80000)*0.45)
m = int(m+0.5)
print(str(m))
第二题
字符串的缩写,连续递增的字符串比如‘ABCD’,改为‘A-D’,要求递增的字符大于四个。
AC50%,好像是时间复杂度过大,答主也不知道是什么问题,求解?
import sys
n = int(sys.stdin.readline().strip())
for i in range(n):
v = sys.stdin.readline().strip()
res = ''
l, r, i = 0, 0, 0
while i < len(v):
if i < len(v)-1 and ord(v[i]) == ord(v[i+1]) - 1:
l = i
r = i + 1
j = i
j += 1
while j < len(v)-1 and ord(v[j]) == ord(v[j+1]) - 1:
r = j + 1
j += 1
if r - l >= 3:
res += v[l]
res += '-'
i = r
res += v[i]
i += 1
print(res)
第三题没有来得及看。。。