文章目录
- 最长连续子序列
- AI面板识别
- 语法知识记录
最长连续子序列
https://www.nowcoder.com/discuss/592408743019589632
if __name__ == "__main__":
# 获取用户输入
# numbers = int(input().split(','))
# str_arr = input().split(',')
arr = [int(num) for num in input().split(',')]
t_sum = int(input())
# 从第一个开始遍历,设定窗口,如果窗口=sum,统计窗口的长度,看是不是最大
n = len(arr)
max_len = -1
for i in range(n):
for j in range(n):
c_sum = sum(arr[i:j + 1])
if c_sum == t_sum:
max_len = max(max_len, j - i + 1)
print(max_len)
AI面板识别
https://www.nowcoder.com/discuss/592418451918970880
python真是简单到离谱…早知道早点用了…
class Light:
def __init__(self, id, x1, y1, x2, y2):
self.id = id
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
if __name__ == "__main__":
# 获取用户输入
# numbers = int(input().split(','))
# str_arr = input().split(',')
# 获取灯的数量
num_lights = int(input("请输入灯的数量:"))
lights = []
for _ in range(num_lights):
# 获取一盏灯的信息
light_info = input("请输入灯的信息(用空格分隔):").split()
light_id, x1, y1, x2, y2 = map(int, light_info)
light = Light(light_id, x1, y1, x2, y2)
lights.append(light)
for light in lights:
print(light.__dict__)
print("-------------------------------------")
lights = sorted(lights, key=lambda l: (l.y1,l.x1))
for light in lights:
print(light.__dict__)