- #include <iostream>
- using namespace std;
- int continumax(char *,char *);
- void main()
- {
- char *instr ="abcd1234efgh43210";
- char *outstr=new char[10];
- int lenmax=0;
- lenmax=continumax(instr,outstr);
- cout<<lenmax<<endl;
- cout<<outstr;
- }
- int continumax(char *instr,char *outstr)
- {
- char *in=instr;
- char *out=outstr;
- char *temp=NULL;
- char *final=NULL;
- int count=0;
- int lenmax=0;
- while(*in!='/0')
- {
- if(*in>47&&*in<58)
- {
- for(temp=in;*in>47&&*in<58;in++)
- {
- count++;
- }
- }
- else
- in++;
- if(count>lenmax)
- {
- lenmax=count;
- final=temp;
- count=0;
- }
- }
- for(int i=0;i<lenmax;i++)
- {
- *out++ = *final++;
- }
- *out='/0';
- return lenmax;
- }
在字符串中找出连续最长的数字串并以参数形式返回,并把这个串的长度返回
最新推荐文章于 2025-11-09 11:42:51 发布
本文介绍了一个C++程序,该程序旨在从一个包含字母和数字的字符串中找出最长的连续数字序列,并返回其长度及具体数值。通过遍历输入字符串并检查每个字符,程序能够识别并记录最长的数字序列。
987

被折叠的 条评论
为什么被折叠?



