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 !