1 solutions

  • 0
    @ 2026-10-18 15:51:33
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 1e4 + 10;
    int a[N];
    
    int main()
    {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
        }
    
        int last = a[1] - 1;  // 上一个元素的值(初始化为不可能出现的值)
        int now = 0;          // 当前平台的长度
        int ans = 0;          // 最长平台的长度
        int best = 0;         // 最长平台对应的元素值
    
        for (int i = 1; i <= n; i++)
        {
            if (a[i] == last)  // 与上一个元素相同,当前平台延长
            {
                now++;
            }
            else               // 遇到新值,开启一个新平台
            {
                last = a[i];
                now = 1;
            }
            if (now > ans)     // 严格大于才更新:保证"最先出现"的平台胜出
            {
                ans = now;
                best = a[i];
            }
        }
    
        cout << best << endl;
        return 0;
    }
    
    

    Information

    ID
    3605
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    1
    Tags
    # Submissions
    17
    Accepted
    3
    Uploaded By