求大神解惑。
  • 板块P1317 低洼地
  • 楼主Delger
  • 当前回复1
  • 已保存回复2
  • 发布时间2024/5/12 18:39
  • 上次更新2024/5/12 21:06:19
查看原帖
求大神解惑。
1354649
Delger楼主2024/5/12 18:39

虽然第一段代码全点通过还是觉得不太对。感觉第二段代码才对。 0 1 0 2 1 2 0 0 2 0 1 1 1 2 5 第一段:

n=int(input())
ls=list(map(int,input().split()))
count=0
for i in range(1,len(ls)-1):  
    if ls[i-1]>=ls[i] and ls[i]<ls[i+1]:
        count+=1
print(count)

输入0 1 0 2 1 2 0 0 2 0 1 1 1 2 5 就出错 第二段

n=int(input())
ls=list(map(int,input().split()))
for j in range(len(ls)-2):
    if ls[j]==ls[j+1]:
        ls.pop(j)
count=0
for i in range(1,len(ls)-1):
    
    if ls[i-1]>ls[i] and ls[i]<ls[i+1]:
        count+=1
print(count)
2024/5/12 18:39
加载中...