-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1notesStore.cs
74 lines (68 loc) · 2.37 KB
/
1notesStore.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.IO;
namespace Solution
{
public class NotesStore
{
public IDictionary<string,string> noteCollection = new Dictionary<string, string>();
public NotesStore() {}
public void AddNote(String state, String name) {
if(name == ""){
throw new Exception("Name cannot be empty");
}else if(state != "completed" && state != "active" && state != "others")
{
throw new Exception($"Invalid state {state}");
}else
{
noteCollection.Add(name, state);
}
}
public List<String> GetNotes(String state) {
List<string> li = new List<string>();
if(state != "completed" && state != "active" && state != "others")
{
throw new Exception($"Invalid state {state}");
}else
{
foreach(KeyValuePair<string, string> kvp in noteCollection)
{
if(state == kvp.Value){
li.Add(kvp.Key);
}
}
}
return li;
}
}
public class Solution
{
public static void Main()
{
var notesStoreObj = new NotesStore();
var n = int.Parse(Console.ReadLine());
for (var i = 0; i < n; i++) {
var operationInfo = Console.ReadLine().Split(' ');
try
{
if (operationInfo[0] == "AddNote")
notesStoreObj.AddNote(operationInfo[1], operationInfo.Length == 2 ? "" : operationInfo[2]);
else if (operationInfo[0] == "GetNotes")
{
var result = notesStoreObj.GetNotes(operationInfo[1]);
if (result.Count == 0)
Console.WriteLine("No Notes");
else
Console.WriteLine(string.Join(",", result));
} else {
Console.WriteLine("Invalid Parameter");
}
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
}
}
}
}
}