質問編集履歴

1

コードを追加しました

2021/10/21 23:34

投稿

fruitpunch
fruitpunch

スコア6

test CHANGED
File without changes
test CHANGED
@@ -15,6 +15,80 @@
15
15
 
16
16
 
17
17
  ```C#
18
+
19
+ static void Main(string[] args)
20
+
21
+ {
22
+
23
+ //テキストファイルの中の単語をリストに
24
+
25
+ string filePath = ("file path");
26
+
27
+
28
+
29
+ List<string> lines = File.ReadAllLines(filePath).ToList();
30
+
31
+
32
+
33
+ Hashtable ht = new Hashtable();
34
+
35
+
36
+
37
+ int count = 1;
38
+
39
+ //time complexity O(n)
40
+
41
+ //because this loop should loop through every single line
42
+
43
+ foreach (string line in lines)
44
+
45
+ {
46
+
47
+ if (ht.ContainsKey(line))
48
+
49
+ {
50
+
51
+ ht[line] = (int)ht[line] + 1;
52
+
53
+
54
+
55
+ }
56
+
57
+ else
58
+
59
+ {
60
+
61
+ ht.Add(line, count);
62
+
63
+ }
64
+
65
+
66
+
67
+ }
68
+
69
+
70
+
71
+ //print hashtable
72
+
73
+ //time complexity O(n)
74
+
75
+ //because this loop should loop through every single line
76
+
77
+ foreach (DictionaryEntry entry in ht)
78
+
79
+ {
80
+
81
+ Console.WriteLine("Key: " + entry.Key + " / " + "Value: " + entry.Value);
82
+
83
+ }
84
+
85
+
86
+
87
+ maxFreq(ht);
88
+
89
+ Console.ReadKey();
90
+
91
+ }
18
92
 
19
93
  public static void maxFreq(Hashtable ht)
20
94