华为OD 山峰个数 C语言实现

不知道是不是我理解错了,这个题目200分?

cpp 复制代码
int main(void)
{
    int i = 0;
    int len = 0;
    char c = '\0';
    int data[1000] = {0};
    int temp[1000] = {-1};
    int top = 0;
    int count = 0;

    while(scanf("%d",&data[i]) == 1)
    {
      i++;
      len++;

      c=getchar();
      if(c == '\n')
      {
          break;
      }
    }

//    for(i=0; i<len; i++)
//    {
//        printf("%d ",data[i]);
//    }
    temp[0]=data[0];

    for(i=1; i<len; i++)
    {
        if(data[i]>temp[top])//入栈
        {
            top++;
            temp[top] = data[i];
            if(i== len-1)
            {
                count++;
                break;
            }
        }
        else//出栈为山峰
        {
            count++;
            top=0;
            temp[top] = data[i];
        }
    }

printf("%d",count);

    return 0;
}
相关推荐
2301_764441335 小时前
LISA时空跃迁分析,地理时空分析
数据结构·python·算法
东北洗浴王子讲AI5 小时前
GPT-5.4辅助算法设计与优化:从理论到实践的系统方法
人工智能·gpt·算法·chatgpt
014-code5 小时前
订单超时取消与库存回滚的完整实现(延迟任务 + 状态机)
java·开发语言
Billlly6 小时前
ABC 453 个人题解
算法·题解·atcoder
玉树临风ives6 小时前
atcoder ABC 452 题解
数据结构·算法
feifeigo1236 小时前
基于马尔可夫随机场模型的SAR图像变化检测源码实现
算法
java1234_小锋6 小时前
Java高频面试题:Springboot的自动配置原理?
java·spring boot·面试
fengfuyao9857 小时前
基于STM32的4轴步进电机加减速控制工程源码(梯形加减速算法)
网络·stm32·算法
末央&7 小时前
【天机论坛】项目环境搭建和数据库设计
java·数据库
枫叶落雨2227 小时前
ShardingSphere 介绍
java