链接: https://pan.baidu.com/s/1Hjt4629OurKTUjNKgxhUvw
提取码: etrt
链接: 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)));
}
}
}