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

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

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

#include <stdio.h>
#include <string.h>

//获取所有数字子串及其长度并存储

int main()
{
  char str[200];
  while (scanf("%s", str) != EOF)
  {
    int strlength = strlen(str);
    char subNumStr[200][200]={0};
    int len[200];
    int top = -1;

    int start = 0, end = 0;

    while (end < strlength)
    {
      while (str[start] < '0' || str[start] > '9')
      {
        start++;
        end++;
      }

      while (str[end] >= '0' && str[end] <= '9')
      {
        end++;
      }
      strncpy(subNumStr[++top], str + start, end - start);
      len[top] = end - start;
      start = end;


    }
    int max = 0;
    for (int i = 0; i <= top; i++)
      if (len[i] > max)
        max = len[i];
    
    for(int i=0;i<=top;i++){
      if(len[i]==max)
      printf("%s",subNumStr[i]);
    }
    printf(",%d\n",max);
  }

  return 0;
}

全部评论

相关推荐

10-29 22:30
吉林大学 Java
同专业学长学姐,去互联网大厂的起薪&nbsp;15k+,去国企&nbsp;IT&nbsp;岗的也有&nbsp;12k+,就连去中小厂的都基本&nbsp;13k&nbsp;起步😤&nbsp;我投的传统行业技术岗,拼死拼活拿到&nbsp;1Woffer,本来还挺开心,结果逛了圈牛客直接破防,同是校招生,行业差距怎么就这么大啊!
喵喵喵6_6:应该哪里不对吧,大厂都是20k以上的,10k那种对于985本的学生基本就是点击一下过了笔试就送的,我前两天刚拿了一个11k,笔试完第2天就打电话了,非科班。坏消息是c++岗开这么低真是刷新认知了
校招生月薪1W算什么水平
点赞 评论 收藏
分享
LXXXXd:有点杂,想搞自动化的话没必要把法律的经历写上去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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