题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
http://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
#include<stdio.h>
#include<string.h>
#define N 200
int main(){
    char str[N];
    while(scanf("%s",str)!=EOF){
        int max=0,count=0;
        for(int i=0;i<strlen(str);i++)
        {
            if(str[i]>='0'&&str[i]<='9')
                count++;
            else
                count=0;
            if(max<count)
                max=count;//找到连续数字个数的最大值
        }
        for(int i=0;i<strlen(str);)
        {
            if(str[i]>='0'&&str[i]<='9')
            {
                int j=i+1;
                while(str[j]&&str[j]>='0'&&str[j]<='9')   j++;
                if(j-i==max)    //根据这个差值进行打印输出所有满足条件的连续数字
                    while(j!=i)
                        printf("%c",str[i++]);
                else 
                    i=j;
            }
            else
                i++;
        }
        printf(",%d\n",max);
    }
    return 0;
}
 查看30道真题和解析
查看30道真题和解析
 投递大疆等公司10个岗位
投递大疆等公司10个岗位