CCF&Python 2016-4-1 折点计数

原题目

CCF&Python 2016-4-1 折点计数CCF&Python 2016-4-1 折点计数

思路

题目看起来很长啊,很唬人,但是不就是看有几个数字满足 大于或小于相邻的两个数字吗?
而且第一个和最后一个数字不用考虑。遍历一遍就完事了

num=int(input())
num_list=list(map(int,input().split()))
result=0

for i in range(1,num-1):
    if (num_list[i-1]>num_list[i]  and num_list[i+1]>num_list[i] )or  (num_list[i-1]<num_list[i]  and num_list[i+1]<num_list[i] ):
        result+=1
print(result)

备注

其实更多的时候感觉CCF是文字阅读题

相关文章:

  • 2021-11-28
  • 2021-06-07
  • 2022-12-23
  • 2022-01-08
  • 2021-11-28
  • 2021-11-18
  • 2021-12-04
  • 2021-06-24
猜你喜欢
  • 2021-10-23
  • 2022-12-23
  • 2022-01-12
  • 2021-05-08
  • 2021-08-22
  • 2021-09-26
  • 2021-09-02
相关资源
相似解决方案