博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在字符串中找出连续最长的数字串
阅读量:6903 次
发布时间:2019-06-27

本文共 897 字,大约阅读时间需要 2 分钟。

hot3.png

题目:

写一个函数,它的原形是 int continumax(char *outputstr,char *intputstr)

功能:

在字符串中找出连续最长的数字串,并把这个串的长度返回,

并把这个最长数字串付给其中一个函数参数 outputstr  所指内存。

例如:"abcd12345ed125ss123456789" 的首地址传给 intputstr 后,函数将返回 9,

outputstr  所指的值为 123456789

题目也比较简单,有一点需要注意

代码实现(GCC编译通过):

#include "stdio.h"#include "stdlib.h"int continumax(char * outputstr,char * inputstr);int main(void){	char *in = "abcd12345ed125dd123456789";	char *out = (char *)malloc(sizeof(char)*100);		int i = continumax(out,in);	printf("%d\n",i);	printf("%s\n",out);	return 0;}int continumax(char * outputstr, char * inputstr){	int len,max,i;	char *p;	len = max = 0;	//若写成while(inputstr != '\0'),当字符串结尾出现最长数字串则无法处理	while(1)	{			if(*inputstr >= '0' && *inputstr <= '9')		{			len++;		}		else		{			if(len >max)			{				max = len;				p = inputstr - len;			}			len = 0;		}		if(*inputstr++ == 0) 			break;	}	for(i = 0;i

转载于:https://my.oschina.net/u/1470003/blog/233644

你可能感兴趣的文章
[awk] 用-F指定多分隔符实例_备忘
查看>>
我的友情链接
查看>>
C++字符串高效查找替换
查看>>
62.菜鸟福音 60条笔记本电脑使用经典技巧
查看>>
mysql全备脚本,此脚本可以备份多个数据库,单独文件夹
查看>>
mysql的双机热备
查看>>
linux第一课
查看>>
Spring3中好用的工具类收集
查看>>
Python用pip 安装lxml时出现 “Unable to find vcvarsall.bat ”解决方案
查看>>
我的友情链接
查看>>
java单例模式之线程安全问题
查看>>
Notes打不开的故障总结
查看>>
WEB打印控件Lodop(V6.x)
查看>>
我的友情链接
查看>>
UI集成测试运行说明
查看>>
ES与Javscript,JScript,ActionScript等脚本
查看>>
断点的技巧
查看>>
mariadb配置安装
查看>>
自己做网站怎么计算带宽需求
查看>>
流镜像,端口镜像
查看>>