华为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;
}
相关推荐
-Rane7 小时前
【C++】vector
开发语言·c++·算法
tianyagukechat7 小时前
rockylinux9.5 配置IP
java·网络·tcp/ip
代码栈上的思考7 小时前
滑动窗口算法实战
算法
程序员Sonder7 小时前
黑马java----正则表达式(一文弄懂)
java·正则表达式·新人首发
doris82047 小时前
Python 正则表达式 re.findall()
java·python·正则表达式
Eloudy7 小时前
直接法 读书笔记 06 第6章 LU分解
人工智能·算法·ai·hpc
Anastasiozzzz7 小时前
阿亮随手记:动态条件生成Bean
java·前端·数据库
仰泳的熊猫8 小时前
题目1531:蓝桥杯算法提高VIP-数的划分
数据结构·c++·算法·蓝桥杯
刘琦沛在进步8 小时前
如何计算时间复杂度与空间复杂度
数据结构·c++·算法
m0_672703318 小时前
上机练习第30天
数据结构·算法