빈도수를 이용하므로 Dictionary를 사용한다.
M값보다 길이가 짧으면 추가하지 않는다.
이후 Dictionary에서 Sort를 한다.
OrderByDescending(x => x.Value).ThenByDescending(x => x.Key.Length).ThenBy(x => x.Key)
namespace SongE
{
public class Program
{
static void Main(string[] args)
{
using var input = new System.IO.StreamReader(Console.OpenStandardInput());
//int intInput() => int.Parse(input.ReadLine());
int[] intsInput() => Array.ConvertAll(input.ReadLine().Split(), s => int.Parse(s));
int[] nm = intsInput();
Dictionary<string, int> dict = new();
for(int i = 0; i < nm[0]; i++)
{
string voca = input.ReadLine();
if (voca.Length >= nm[1])
{
if(!dict.TryAdd(voca, 0))
{
dict[voca]++;
}
}
}
SortDict(dict);
}
static void SortDict(Dictionary<string, int> dict)
{
using var print = new System.IO.StreamWriter(Console.OpenStandardOutput());
var sorted = dict.OrderByDescending(x => x.Value).ThenByDescending(x => x.Key.Length).ThenBy(x => x.Key).ToDictionary(x=>x.Key, x=>x.Value);
foreach(string voca in sorted.Keys)
{
print.WriteLine(voca);
}
}
}
}