C语言程序设计问题(高手帮下忙)

来源:百度知道 编辑:UC知道 时间:2024/05/17 12:57:24
给定一个已升序排好的整数数组,求得此数组的最长平台的长度。所谓平台就是数组中连续相等的元素组合。如X[]={1,2,3,3,4,4,5,5,5,6}则此数组当中有1,2,33,44,555,6共六个平台,最长平台为555,长度为3。

#include <stdio.h>

int fun(int x[],int size)
{
int * p0,* p1,* pos;
p1=p0=x;
int max=0;
while(p1<x+size)
{
if(* p1==* p0)
p1++;
else
{
if(p1-p0>max)
{
max=p1-p0;
pos=p0;
}
p0=p1;
}
}
for(p0=pos;p0<pos+max;p0++)
printf("%d",* p0);
printf("\n");
return max;
}

void main()
{
int X[]={1,2,3,3,4,4,5,5,5,6};
printf("%d\n",fun(X,sizeof(X)/sizeof(int)));
}

#include <stdio.h>
#include <stdlib.h>
#define max 20

int main(int argc, char *argv[])
{int N,arr[max];
int arr1[max][max]={0};
int k,j,i,count;
int m=0,max1=0;
printf("please input total number:");
scanf("%d",&N);
for(i=0;i<N;i++)
scanf("%d",&arr[i]);
for(i=0;i<N