質問編集履歴
1
コードを追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,6 +7,43 @@
|
|
7
7
|
### 該当のソースコード
|
8
8
|
|
9
9
|
```C#
|
10
|
+
static void Main(string[] args)
|
11
|
+
{
|
12
|
+
//テキストファイルの中の単語をリストに
|
13
|
+
string filePath = ("file path");
|
14
|
+
|
15
|
+
List<string> lines = File.ReadAllLines(filePath).ToList();
|
16
|
+
|
17
|
+
Hashtable ht = new Hashtable();
|
18
|
+
|
19
|
+
int count = 1;
|
20
|
+
//time complexity O(n)
|
21
|
+
//because this loop should loop through every single line
|
22
|
+
foreach (string line in lines)
|
23
|
+
{
|
24
|
+
if (ht.ContainsKey(line))
|
25
|
+
{
|
26
|
+
ht[line] = (int)ht[line] + 1;
|
27
|
+
|
28
|
+
}
|
29
|
+
else
|
30
|
+
{
|
31
|
+
ht.Add(line, count);
|
32
|
+
}
|
33
|
+
|
34
|
+
}
|
35
|
+
|
36
|
+
//print hashtable
|
37
|
+
//time complexity O(n)
|
38
|
+
//because this loop should loop through every single line
|
39
|
+
foreach (DictionaryEntry entry in ht)
|
40
|
+
{
|
41
|
+
Console.WriteLine("Key: " + entry.Key + " / " + "Value: " + entry.Value);
|
42
|
+
}
|
43
|
+
|
44
|
+
maxFreq(ht);
|
45
|
+
Console.ReadKey();
|
46
|
+
}
|
10
47
|
public static void maxFreq(Hashtable ht)
|
11
48
|
{
|
12
49
|
string key = "";
|