65,211
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
void continuedNumb(int* a,int N)
{
int *firP = a,*secP = a;
int i = 0;
while (i < N)
{
if (*(++secP) == *firP)
{
;
}
else
{
if ((secP - firP) > 1)
{
cout<<*firP<<"have"<<(secP - firP)<<endl;
}
firP = secP;
}
i++;
if (i == (N-1) && (secP - firP) > 1)
{
cout<<*firP<<"have"<<(secP - firP)<<endl;
}
}
}
int main()
{
int a[]={1,1,2,3,4,4,1,1,1,2,2};
continuedNumb(a,sizeof(a)/sizeof(int));
return 0;
}
#include <stdio.h>
#define N 11
void count(int arr[], int n)
{
int last = arr[0];
int count = 0;
for (int i = 0; i < n; i++)
{
if (arr[i] == last)
{
count++;
}
else
{
printf("%d 有 %d 个\n", last, count);
count = 1;
last = arr[i];
}
}
printf("%d 有 %d 个\n", last, count);
}
int main()
{
int arr[N]={1, 1, 2, 3, 4, 4, 1, 1, 1, 2, 2};
count(arr, N);
return 0;
}