Created
December 17, 2022 18:56
-
-
Save QuiltMeow/b07d837959761721ccbdcfb1196edb68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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