您当前的位置: 首页 >  华为

qq_34412985

暂无认证

  • 0浏览

    0关注

    1061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

《牛客网》——华为机试在线训练——找最长连续数字串

qq_34412985 发布时间:2021-03-04 10:37:52 ,浏览量:0

例如输入:abcd123.4567.890.123

输出:123.4567.890

“.”可以作为连接符连接两个数字,但是要求"."两边必须都是数字。

面试时遇到的题,因为忽略了对‘0’的处理,所以挂了。

#include
#include

#define MAX_SIZE 0x500

bool IsDotCorrect(char*szInput, int i, int nLastCmpPos, int nLen)//Check if it's a correct dot.
{
    if (nLastCmpPos < 0)
    {
        return false;
    }

    if ((i - 1 >= 0 && i + 1 = '0' && szInput[i - 1] = '0' && szInput[i + 1] = '0' && szInput[i] = 0)//if it's first correct char, no need to compare
                {
                    if (nCount == 0) //first num in this loop ,no need to compare
                    {
                        nCount++;
                    }
                    else
                    {
                        if (((szInput[i] - szInput[nLastCmpPos]) == 1) && szInput[nLastCmpPos] != '0')
                        {
                            nCount++;
                        }
                        else if (szInput[i] == '0' && szInput[nLastCmpPos] == '9')
                        {
                            nCount++;
                        }
                        else
                        {
                            bIsCount = false;
                        }

                        /*if (szInput[i] == '0' && szInput[nLastCmpPos] == '9')
                        {
                        nCount++;
                        }*/
                        
                    }
                }
                else//first num ++
                {
                    nCount++;
                }
                nLastCmpPos = i;
            }

            if (!bIsCount)//Count start
            {
                bIsCount = false;//Count again

                if (nCountBak             
关注
打赏
1653291990
查看更多评论
立即登录/注册

微信扫码登录

0.0457s