一只猪


私信TA

用户名:TuT99

访问量:6715

签 名:

拥有良好的积累,并且一直在路上,我相信自己有无限的可能

等  级
排  名 74
经  验 9600
参赛次数 6
文章发表 66
年  龄 21
在职情况 学生
学  校 哔哩哔哩大学
专  业 计算机科学与技术

  自我简介:


参考代码:

#include <iostream>

#include <vector>

using namespace std;


int main() {

    int n;

    cin >> n;  // 数组元素的个数


    vector<int> nums(n);

    for (int i = 0; i < n; i++) {

        cin >> nums[i];  // 数组元素

    }


    int max_length = 0;  // 最长平台的长度

    int current_length = 1;  // 当前平台的长度


    // 遍历数组,寻找最长平台

    for (int i = 1; i < n; i++) {

        if (nums[i] == nums[i - 1]) {  // 平台延伸

            current_length++;

        } else {  // 平台结束

            max_length = max(max_length, current_length);

            current_length = 1;

        }

    }


    max_length = max(max_length, current_length);  // 处理结尾的平台


    cout << max_length << endl;


    return 0;

}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

if (n>0)
    current_length=1;
else
    current_length=0;
2024-04-02 12:03:15
  • «
  • 1
  • »