题解 | #在字符串中找出连续最长的数字串#

在字符串中找出连续最长的数字串

https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() 
{
    char arr[200] = "";
    while (scanf("%s", arr) != EOF) 
    {
        int max = 0;
        int count = 0;
        for (int i = 0; i < strlen(arr); i++) 
        {
            if (isdigit(arr[i])) 
                count++;
            else
                count = 0;
            max=max>count?max:count;
        }
        for(int i=0;i<strlen(arr);i++)
        {
            if(isdigit(arr[i]))
            {
                int j=i+1;
                while(isdigit(arr[j]) && arr[j])
                    j++;
                if(j-i==max)
                    while(j!=i)
                        printf("%c",arr[i++]);
                else
                    i=j;
            }
        }
        printf(",%d\n",max);
    }
    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
06-07 19:59
门头沟学院 C++
补药卡我啊😭:都快15年前的了还在11新特性
你的简历改到第几版了
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务