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

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

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

#include<stdio.h>
int main() {
    char str[201];
    while (~scanf("%s", str)) {
        int i = 0, j = 0, mlen = 0;
        while (str[i]) {
            if (str[i] >= '0' && str[i] <= '9') {
                j = i + 1;
                while (str[j] && str[j] >= '0' && str[j] <= '9')j++;
                mlen = j - i > mlen ? j - i : mlen;
                i = j;
            }
            else {
                i++;
            }
        }
        i = 0;
        while (str[i]) {
            if (str[i] >= '0' && str[i] <= '9') {
                j = i + 1;
                while (str[j] && str[j] >= '0' && str[j] <= '9')j++;
                if (j - i == mlen)
                    while (i != j)
                        printf("%c", str[i++]);
                else
                    i = j;
            }
            else {
                i++;
            }
        }
        printf(",%d\n", mlen);
    }
}
全部评论

相关推荐

02-23 00:10
湖南大学 C++
点赞 评论 收藏
分享
03-27 15:39
算法工程师
几乎所有大中厂都挂了,现在压力拉满了。。。
下辈子转生为少女乐队女主人公:同全挂,想去考研逃避现实了
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客企业服务