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

  1.  #include <iostream>
  2. using namespace std;
  3. int continumax(char *,char *);
  4. void main()
  5. {
  6.  char *instr ="abcd1234efgh43210";
  7.  char *outstr=new char[10];
  8.  int lenmax=0;
  9.  lenmax=continumax(instr,outstr);
  10.  cout<<lenmax<<endl;
  11.  cout<<outstr;
  12. }
  13. int continumax(char *instr,char *outstr)
  14. {
  15.  char *in=instr;
  16.  char *out=outstr;
  17.  char *temp=NULL;
  18.  char *final=NULL;
  19.  int count=0;
  20.  int lenmax=0;
  21.  while(*in!='/0')
  22.  {
  23.   if(*in>47&&*in<58)
  24.   {
  25.    for(temp=in;*in>47&&*in<58;in++)
  26.    {
  27.     count++;
  28.    }
  29.   }
  30.   else
  31.    in++;
  32.   
  33.   if(count>lenmax)
  34.   {
  35.    lenmax=count;
  36.    final=temp;
  37.    count=0;
  38.   }
  39.  }
  40.  for(int i=0;i<lenmax;i++)
  41.  {
  42.   *out++ = *final++;
  43.  }
  44.  *out='/0';
  45.  return lenmax;
  46. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值