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

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

提取码: etrt 

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

 

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)));
        }
    }
}

 

sample input #2.  The correct output begins

 

7 'E': The ribboned stick, the bellowing breeches, cloak

6 'E': Could Crispin stem verboseness in the sea,

6 'E': The lutanist of fleas, the knave, the thane,

...

 

but your program produces

 

7 'E': The ribboned stick, the bellowing breeches, cloak

6 'S': Could Crispin stem verboseness in the sea,

6 'T': The lutanist of fleas, the knave, the thane,