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

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

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

#include <stdio.h> #include <string.h> int main() { int i; char str[201]; while(scanf("%s",str)!=EOF){ int begin,max=0,count=0,flag; char store[200][201]; for(i=0;i<strlen(str);i++) {

        begin=i;
        flag=0;
        while(str[begin]>='0'&&str[begin]<='9')
        {
            store[count][begin-i]=str[begin];
            begin++;
            flag++; 
        }
        store[count][begin-i]='\0';
        count++;
    if(max<flag)
    {
        max=flag;
    }
    
}
   for(i=0;i<=count;i++)
    {
        if(strlen(store[i])==max)
        printf("%s",store[i]);
    }
    printf(",%d\n",max);
}
return 0;

}

全部评论

相关推荐

04-28 11:34
西北大学 运营
牛客4396号:不好意思,这个照片猛一看像丁真
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务