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

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

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {
        string line1;
        var inputList = new List<string>();
        while (!string.IsNullOrWhiteSpace(line1 = Console.ReadLine()))
        {
            inputList.Add(line1);
        }
        foreach (var item in inputList)
        {
            var newStr = Regex.Replace(item, $"[^\\d]", "#").Replace("##", "#");
            var li = newStr.Split("#");
            var all_item = li.GroupBy(a=>a.Length).OrderByDescending(a=>a.Key).ToList();
            var res_item = li.Where(a => a.Length == all_item[0].Key).ToList();
            Console.WriteLine(string.Join("", res_item)+","+res_item[0].Length);
        }
    }
}

全部评论

相关推荐

04-18 15:58
已编辑
门头沟学院 设计
kaoyu:这一看就不是计算机的,怎么还有个排斥洗碗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务