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

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

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-25 09:33
厦门大学 Java
程序员饺子:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司7个岗位
点赞 评论 收藏
分享
06-18 13:28
已编辑
门头沟学院 Web前端
爱睡觉的冰箱哥:《给予你300的工资》,阴的没边了
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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