编写一个函数,有如下函数原型: 函数:int continum(char *intputstr,char *outputstr). 给一个字符串,要求找到里面连续的串,并且串的长度是所有连续串中
2018-02-20 20:14
1236 查看
编写一个函数,有如下函数原型:#include <stdio.h>
#include <string.h>
int continumax(char*outputstr,char*intputstr)
{
int start=0,end=0,max=0; //start是数字字符的起始位置 end是数字字符的结束位置 max数字字符串字符的个数
int tempstart=0,tempmax=0; //tempstart任意数字字符的起始位置 tempmax任意数字字符串字符的个数
int length=strlen(intputstr);//整个字符串的大小
int cur=0;
for(;cur<length;cur++)//遍历整个字符串
{
char c=intputstr[cur];
if(c>='0'&&c<='9')//当字符是数字时
{
if(tempmax==0)
{
tempstart=cur;//新的数字字符串的起始位置
}
tempmax++;
}
else//当不是数字时
{
if(tempmax>max)
{
start=tempstart;
end=cur;
max=tempmax;
tempmax=0;
}
}
}
for(cur=0;cur<end-start;cur++)
{
outputstr[cur]=intputstr[cur+start];
putchar(outputstr[cur]);
}
putchar('\n');
return max;
}
int main(int argc, const char *argv[])
{
char arr[100];
memset(arr,0,sizeof(arr));
printf("please input a string:");
gets(arr);
char out[100];
memset(out,0,sizeof(out));
int len=continumax(out,arr);
printf("len=%d\n",len);
return 0;
}
函数:int continum(char *intputstr,char *outputstr).
给一个字符串,要求找到里面连续的串,并且串的长度是所有连续串中最长的;结果是返回最长连续串的长度和对应的串;
例如:有字符串“abc123ef456ss123456789”其首地址是intputstr,最长的连续串是 123456789,长度是9,该串由outputstr返回。
#include <string.h>
int continumax(char*outputstr,char*intputstr)
{
int start=0,end=0,max=0; //start是数字字符的起始位置 end是数字字符的结束位置 max数字字符串字符的个数
int tempstart=0,tempmax=0; //tempstart任意数字字符的起始位置 tempmax任意数字字符串字符的个数
int length=strlen(intputstr);//整个字符串的大小
int cur=0;
for(;cur<length;cur++)//遍历整个字符串
{
char c=intputstr[cur];
if(c>='0'&&c<='9')//当字符是数字时
{
if(tempmax==0)
{
tempstart=cur;//新的数字字符串的起始位置
}
tempmax++;
}
else//当不是数字时
{
if(tempmax>max)
{
start=tempstart;
end=cur;
max=tempmax;
tempmax=0;
}
}
}
for(cur=0;cur<end-start;cur++)
{
outputstr[cur]=intputstr[cur+start];
putchar(outputstr[cur]);
}
putchar('\n');
return max;
}
int main(int argc, const char *argv[])
{
char arr[100];
memset(arr,0,sizeof(arr));
printf("please input a string:");
gets(arr);
char out[100];
memset(out,0,sizeof(out));
int len=continumax(out,arr);
printf("len=%d\n",len);
return 0;
}
函数:int continum(char *intputstr,char *outputstr).
给一个字符串,要求找到里面连续的串,并且串的长度是所有连续串中最长的;结果是返回最长连续串的长度和对应的串;
例如:有字符串“abc123ef456ss123456789”其首地址是intputstr,最长的连续串是 123456789,长度是9,该串由outputstr返回。
相关文章推荐
- 第25题: 写一个函数,它的原形是int continumax(char *outputstr,char *intputstr),在字符串中找出连续最长的数字串,并把这个串的长度返回
- 【微软100题】写一个函数,它的原形是int continumax(char *outputstr,char *intputstr) 功能: 在字符串中找出连续最长的数字串,并把这个串的长度返回
- 【练习】写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)功能:在字符串中找出连续最长的数字串,并把这个串的长度返回,
- 编写一个函数,它从一个字符串中提取一个子字符串。函数原型如下: Int substr(char dst[], char src[],int start, int len) {} 目标是:从src数组
- 25.写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)
- 写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)
- 第25 题: 写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)
- 第25 题:写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)
- 编写一个函数,删除字符串中的一段字符,函数原型为: int fun(char *p,int start,int end); 返回值为删除字符数, start 开始位置,end 结束位置。
- 写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)
- 25.写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)
- 写一个函数,它的原形是int continumax(char*outputstr,char*intputstr)
- 微软面试100题之25题:写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)
- 算法习题25:写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)
- 为下面的函数原型编写函数定义: int ascii_to_integer(char *str); 这个字符串参数必须包含一个或者多个数字,函数应该把这些数字字符转换为整数并返回这个整数。如果字符串参数
- 在一个长度为10的整型数组里面,保存了班级10个学生的考试成绩。要求编写5个函数,分别实现计算考试的总分,最高分,最低分,平均分和考试成绩降序排序
- 函数在一个字符串中进行搜索,查找所有在一个给定字符集合中出现的字符,函数原型:char *find_char( char const *source, char const *chars);
- 【c语言】编写一个函数reverse_string(char * string) 实现:将参数字符串中的字符反向排列。 要求:不能使用C函数库中的字符串操作函数
- 编写一个函数,将一个数字字符串转换成这个字符串对应的数字(包括正浮点数、负浮点数);函数原型:double my_atof(char *str)
- 编写一个函数reverse_string(char * string) 实现:将参数字符串中的字符反向排列。 要求:不能使用C函数库中的字符串操作函数。