基于visual Studio2013解决面试题之0908最大连续数字串




题目



解决代码及点评

 
 
 
 
/*
	求最大连续递增数字串(如"ads3sl456789DF3456ld345AA"中的"456789")

	这道题的解法还是从头到尾的遍历即可
*/

#include <iostream>
using namespace std;

int FindMaxLen(char *pszBuf, char *pszOutPut)
{
    int nMaxLen = 0;
    int nTmpLen = 0;
    int nTmpPos;
    int nMaxPos;
    int i, j;
    if (pszBuf == NULL)
    {
        return 0;
    }
    for (i = 0; i < strlen(pszBuf); i++)
    {
        nTmpLen = 0;
        if (pszBuf[i] >= '0' && pszBuf[i] <= '9')
        {
            nTmpPos = i;
            nTmpLen++;
            while(pszBuf[i] >= '0' && pszBuf[i] <= '9'&&
                i < strlen(pszBuf) && pszBuf[i] < pszBuf[i+1]&&
                pszBuf[i+1] >= '0' && pszBuf[i+1] <= '9')
            {
                nTmpLen++;
                i++;
            }
            if(nTmpLen > nMaxLen)
            {
                nMaxLen = nTmpLen;
                nMaxPos = nTmpPos;
            }
        }
    }
    for (i = nMaxPos, j = 0; i < nMaxPos + nMaxLen; i++)
    {
        pszOutPut[j++] = pszBuf[i];
    }

    return nMaxLen;
}

int main()
{
    char szBuf1[] = "ads3sl456789DF3456ld345AA";
    char szBufOut[100] = {0};
    int nLen = FindMaxLen(szBuf1, szBufOut);
    cout<<"最大连续递增数字串为:"<<szBufOut<<endl;
    system("pause");
    return 0;
}

代码下载及其运行

代码下载地址:http://download.csdn.net/detail/yincheng01/6704519

解压密码:c.itcast.cn


下载代码并解压后,用VC2013打开interview.sln,并设置对应的启动项目后,点击运行即可,具体步骤如下:

1)设置启动项目:右键点击解决方案,在弹出菜单中选择“设置启动项目”


2)在下拉框中选择相应项目,项目名和博客编号一致

3)点击“本地Windows调试器”运行


程序运行结果









转载于:https://www.cnblogs.com/new0801/p/6177325.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值