📄 zhongshu.cpp
字号:
#include <iostream>
#include<stdio.h>
using namespace std;
void statistic(double *b,int k,double *value);
int main (int argc, char *argv[])
{
double b[10]={2,2,2,3,4,4,4,4,5,6};
int maxtimes;
double *value;
value = new double[2];
statistic(b,10,value);
printf("the max %f,occur %.0f times",value[0],value[1]);
cin.get();
delete[] value;
return 0;
}
void statistic(double *b,int k,double *value)
{
double *a,*count;
int m=0,num=0,maxid,i;
a = new double[k];
count = new double[k];
a[0]=b[0];
int maxtimes = 0;
for(i=0;i<k;i++)
{if(a[m]==b[i])
{num++;
}
else
{ count[m]=num;
if(maxtimes<num)
{maxtimes=num;
maxid = m;}
a[++m]=b[i];
num=1;
}
}
count[m] = num;
if(num>maxtimes)
{maxtimes = num;
maxid = m;
}
value[0] = a[maxid];
value[1] = maxtimes;
delete[] a;
delete[] count;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -