C语言作业题 哪位大哥会的帮忙做一题 thank you thank you

来源:百度知道 编辑:UC知道 时间:2024/05/24 19:44:30
一、程序填空题 str是一个由字符0和1组成的字符系列。请补充函数proc,该函数的功能是:查找该字符序列中0字符连续出现的最长长度(即0字符的个数),如果有几个0字符串长度相同,只记录最后一个0字符串的相关信息。通过m和k返回最长0字符串的长度和起始、结束0字符的下标。例如,若输入“0100001000”,则结果为:0字符串最长长度为4,起始和结束下标分别为2、5。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数proc的横线上填入所编写的若干表达式或语句。 试题程序: #include <stdlib.h> #include <stdio.h> #include <conio.h> #define M 80 void proc(【1】) { int i, j=0; int bb〔M〕; char *p=str; *m=0; *k=0; for (i=0;i<M;i++) bb〔i〕=0; i=0; while(*(p+i)) { if(*(p+i)==‘0’) { 【2】; i++; } else { j++; i++; } if (【3】) { *m=bb〔j〕; *k=i-1; } } } void main() { char str〔M〕; int m,k; system("CLS"); printf("***input the original string ***\n"); gets(str); printf("***The Original string ***\n"); puts(str); proc(str,&m,&k); printf("\nThe length of ‘0’ is: %d\n",m); printf("*** The suffix of character ***\n"); printf(" %d,%d",k-m+1,k); }

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define M 80
void proc(char str[M], int *m, int *k) //参数,不多说了吧
{
int i, j = 0;
int bb[M];
char *p = str;
*m=0; *k=0;
for (i = 0;i < M;i++)
bb[i] = 0;
i = 0;
while(*(p + i))
{
if(*(p+i) == '0')
{
bb[j]++; //记录每一段连续的 ‘0’ 的个数
i++;
}
else
{
j++;
i++;
}
if (*m < bb[j]) //取个数最多的那一段记录
{
*m = bb[j];
*k = i-1;
}
}
}
int main()
{
char str[M];
int m,k;
system("CLS");
printf("***input the original string ***\n");
gets(str);
printf("*