逐至 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 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题