逐至 2021-04-19 11:30 采纳率: 100%
浏览 87
已结题

c#编程题2,进链接看文本,会的留下代码,带注释,感谢

链接: https://pan.baidu.com/s/1Hjt4629OurKTUjNKgxhUvw

提取码: etrt 

  • 写回答

2条回答 默认 最新

  • Go 旅城通票 2021-04-19 13:59
    关注

    马虎了,输出少了个冒号。。。用下面改过的。。

     

    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    namespace ConsoleApp1
    {
        class Program
        {
            public class Line
            {
                public string s { get; set; }
                public Dictionary<char, int> charCount { get; set; }
            }
            static void Main(string[] args)
            {
                var lines = new List<Line>();
                string sLine;
                while (true)
                {
                    sLine = Console.ReadLine();
                    if (sLine == null)
                        break;
                    lines.Add(new Line { s = sLine, charCount = new Dictionary<char, int> { } });
                }
    
    
                var re = new Regex(@"[a-z]+", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                foreach (var line in lines)
                {
                    var mc = re.Matches(line.s);
                    foreach (Match m in mc)
                    {
                        var chrs = m.Value.ToUpper().ToCharArray();
                        foreach (var c in chrs)
                        {
                            if (line.charCount.ContainsKey(c)) line.charCount[c]++;
                            else line.charCount.Add(c, 1);
                        }
                    }
                }
    
                var rs = lines.SelectMany(i =>
                {
                    return i.charCount.OrderByDescending(k=>k.Value).Take(1).Select(k => new { i.s, k.Key, k.Value });
    
                }).OrderByDescending(i => i.Value).ThenBy(i => i.s).Take(10);
    
                Console.Write(String.Join("\n", rs.Select(r => r.Value + " '" + r.Key + "': " + r.s)));
            }
        }
    }
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭