# 第一题：计算出租车的实际里程

5

4

15

13

``````n = int(input())
m = 0
more = 0
while m < n:
# 不知道4会出现在个、十、百、千、万哪儿个位置
if '4' in str(m):
this_m = int(str(m).replace("4", "5"))
if this_m <= n:
more += this_m - m
m = this_m
else:
break
else:
m += 1
print(n-more)
# 此答案用例通过率90%，执行时间超时了
``````

# 第二题：求数组中最大N个与与最小N个数的和

N的值

5
95 88 83 64 100
2

342

``````a = int(input())
b = [int(x) for x in input().split(" ")]
b = list(set(b))
b.sort()
c = int(input)
max_n = []
min_n = []
if len(b) < c*2:
print(-1)
else:
max_n = b[-c:]
min_n = b[:c]
print(sum(max_n) + sum(min_n))
# 此答案用例通过率84%，占用内存超过了限定值
``````

# 第三题：求最长子串长度

abc123ABC

4

``````import re
s = input()
# 通过正则找出所有连续的数字子串（考完之后想了下，其实不如改成双指针遍历的方法去找最长数字子串）
pattern = re.compile(r'\d+')
arr = pattern.findall(s)
if not arr:
print(-1)
else:
max_n = arr[0]
for i in arr:
if len(i) > len(max_n):
max_n = i
index_start = s.index(max_n)
if index_start - 1 >= 0 and s[index_start-1] in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
print(len(max_n)+1)
elif index_start + len(max_n) <= len(s)-1 and s[index_start + len(max_n)] in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
print(len(max_n)+1)
else:
print(-1)
# 此答案用例通过率79%，占用内存超过了限定值
``````