1018,hp1018

來源:互聯網
上載者:User

1018,hp1018

最長平台

Time Limit:1000MS  Memory Limit:65536K
Total Submit:225 Accepted:92

Description

已知一個已經從小到大排列好的數組,說這個數組中的一個平台
(Plateau),就是連續的一串值相同的元素,並且這一串元素不能再延
伸。例如,在 1,2,2,3,3,3,4,5,5,6 中 1,2.2,3.3.3,4,
5.5,6 都是平台。試編寫一個程式,接收一個數組,把這個數組中最長的
平台找出來。在上面的例子中 3.3.3 是該數組中最長的平台。(註:為了
方便,測試案例的數組最大長度都不超過 50,數組中的元素全部為整數範
圍為[-2^31,2^31-1])。

Input

多組測試資料,處理到檔案結尾。每組資料首先由一個數組的長度 L,隨後
跟隨 L 個該數組資料群組成。

Output

對於每個測試案例輸出它的最長平台

Sample Input

101 2 2 3 3 3 4 5 5 6111 1 1 1 1 1 2 2 2 2 251 2 3 4 5

Sample Output

361

Source

ahstu@ICPC02

    using System;    using System.Collections.Generic;    using System.Linq;    using System.Text;    namespace AK1018 {        class Program {            static void Main(string[] args) {                string sb;                while ((sb = Console.ReadLine()) != null) {                    int n = int.Parse(sb);                    int[] a = new int[10005];                    string[] s = Console.ReadLine().Split();                    for (int i = 0; i < n; i++)                        a[i] = int.Parse(s[i]);                    int count = 1;                    for (int i = 1; i < n; i++) {                        if (a[i] == a[i - count])                            count++;                    }                    Console.WriteLine(count);                }            }        }    }


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。Welcome to share your nice codes !

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.