|  | 
| 这是我个人的代码: ————————————————————————
 #include <iostream>
 #include <cstdio>
 using namespace std;
 
 //寻找最长的平台函数
 void function( const int *Array, int Length );
 
 int main()
 {
 //定义平台
 int Plateau[10] = {1,2,2,3,3,3,4,5,5,6};
 
 function(Plateau, 10);
 return 0;
 }
 
 
 void function( const int* Array, int Length )
 {
 //n1:最长的平台
 //n2:当前检测的平台
 //l1:最长的平台的长度
 //l2:当前平台的长度
 int n1 = Array[0], n2 = Array[0], l1 = 0, l2 = 0;
 
 //遍历所有平台
 for( int i = 0; i < Length - 1; i++ )
 {
 if(Array == n2)
 {
 //检测当前平台的长度
 l2++;
 if(l2 > l1)
 {
 //更新最长的平台
 l1 = l2;
 n1 = n2;
 }
 }
 else
 {
 //更换当前平台
 n2 = Array;
 l2 = 1;
 }
 }
 //输出最长的平台
 cout << "最长的平台是:";
 
 for( int j = 0; j < l1; j++ )
 cout << n1 << " ";
 cout << endl;
 }
 | 
 |