Skip to content

Instantly share code, notes, and snippets.

@QuiltMeow
Created December 17, 2022 18:56
Show Gist options
  • Save QuiltMeow/b07d837959761721ccbdcfb1196edb68 to your computer and use it in GitHub Desktop.
Save QuiltMeow/b07d837959761721ccbdcfb1196edb68 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
namespace Stat
{
public static class Program
{
private const string FILE_NAME = "Data.txt";
private static readonly IDictionary<string, int> stat = new Dictionary<string, int>();
public static void Main()
{
try
{
foreach (string line in File.ReadLines(FILE_NAME))
{
if (string.IsNullOrWhiteSpace(line.Trim()))
{
continue;
}
if (stat.ContainsKey(line))
{
++stat[line];
}
else
{
stat.Add(line, 1);
}
}
foreach (KeyValuePair<string, int> pair in stat)
{
Console.WriteLine($"{pair.Key} : {pair.Value}");
}
}
catch (Exception ex)
{
Console.WriteLine($"發生例外狀況 : {ex.Message}");
}
Console.Write("請按任意按鍵繼續 ... ");
Console.ReadKey(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment