真被自己蠢到了,最后一题提交的时候忘记删除一个调试打印语句,凉凉,白给!
下面是考试的一些程序:
code1.py
nums = [int(i) for i in list(input().split(' '))]
N = nums[0]
M = nums[1]
total = []
for i in range(N+1,M):
value = i * (i+1) * (i-1)
if i % 5 == 0:
total.append(i)
if (len(total) >= 3):
print("{} {} {}".format(total[0],total[1],total[2]))
elif (len(total) == 1):
print("{} {} {}".format(total[0],-1,-1))
elif (len(total) == 2):
print("{} {} {}".format(total[0], total[1], -1))
else:
print("{} {} {}".format(-1, -1, -1))
code2.py
nums = [int(i) for i in list(input().split(' '))]
N = nums[0]
M = nums[1]
numbers = [int(i) for i in list(input().split(' '))]
max_value =[]
count = []
# N=10,M=4时,i可以最大取值N[6],即0~6共7个数
# 1 2 3 4 5 6 7 8 9 10
for i in range(0,N-M+1):
# 现在依次取M个数
total = 0
# 4*numbers[i] + (1+2+……M-1)
true_value = M * numbers[i]
for j in range(i,i+M):
total += numbers[j]
for j in range(M):
true_value += j
# 如果满足下式说明就是连续的M个数
if true_value == total:
max_value.append(total)
count.append(i+1)
value = max(max_value)
for i in range(len(max_value)):
if max_value[i] == value:
print("{} {}".format(max_value[i],count[i]))
code3.py
string = input()
# abcadiasiqacdfgiikkg
max_strings = []
# 输入是'a'~'z'构成的,因此无需考虑特殊字符
max_child_string = ""
for i in range(len(string)-1):
if ord(string[i]) <= ord(string[i+1]):
max_child_string += string[i]
else:
max_strings.append(max_child_string)
max_child_string = ""
lengths = []
for str1 in max_strings:
lengths.append(len(str1))
max_length = max(lengths)
for str1 in max_strings:
if len(str1) == max_length:
# 现在需要判断str1在string中的位置
if ord(string.split(str1)[-1][0]) >= ord(str1[-1]):
str1 += string.split(str1)[-1][0]
print(str1)
code4.py
nums = int(input())
totals = []
for i in range(nums):
numbers = [int(i) for i in list(input().split(' '))]
totals.append(numbers)
# 现在数据已经保存到totals里面
"""
6
0 3 0 0 1 1
0 6 0 1 1 1
9 9 9 7 5 3
6 5 3 5 3 3
5 6 6 6 7 6
3 4 4 5 5 5
"""
EOF = -1
# 边界不满足
for i in range(1,len(totals)-1):
for j in range(1,len(totals[0])-1):
"""
假设现在是第i+1行、第j+1列
那么现在取得数据是totals[i][j]
那么左边的数据是totals[i][j-1]
右边的数据是totals[i][j+1]
上面的数据是totals[i-1][j]
下面的数据是totals[i+1][j]
"""
if ((totals[i][j] < totals[i][j-1]) and (totals[i][j] < totals[i][j+1]) and (totals[i][j] < totals[i-1][j]) and (totals[i][j]) < totals[i+1][j]):
print("{} {}".format(i+1,j+1))
EOF = 1
break
if EOF == -1:
print("{} {}".format(-1,-1))