예제 #1
0
 private static void ExecuteElementsCommand(TwoKeysDictionary <int, int, int> twoKeysDictionary)
 {
     foreach (Tuple <int, int, int> twoKeyValuePair in twoKeysDictionary)
     {
         AppendLine($"First Key: {twoKeyValuePair.Item1}, Second Key: {twoKeyValuePair.Item2}, Value: {twoKeyValuePair.Item3}");
     }
 }
예제 #2
0
        private static void ExecuteContainsCommand(string[] tokens, TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            int  key1     = int.Parse(tokens[1]);
            int  key2     = int.Parse(tokens[2]);
            bool contains = twoKeysDictionary.Contains(key1, key2);

            AppendLine(contains.ToString());
        }
예제 #3
0
        private static void ExecuteRemoveCommand(string[] tokens, TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            int  key1      = int.Parse(tokens[1]);
            int  key2      = int.Parse(tokens[2]);
            bool isRemoved = twoKeysDictionary.Remove(key1, key2);

            AppendLine(isRemoved.ToString());
        }
예제 #4
0
        public static void Main(string[] args)
        {
            TwoKeysDictionary <int, int, int> twoKeysDictionary = new TwoKeysDictionary <int, int, int>();

            ExecuteCommands(twoKeysDictionary);

            Console.WriteLine(outputBuilder.ToString().TrimEnd());
        }
예제 #5
0
        private static void ExecuteAddCommand(string[] tokens, TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            int key1  = int.Parse(tokens[1]);
            int key2  = int.Parse(tokens[2]);
            int value = int.Parse(tokens[3]);

            bool isCommandSuccessful = twoKeysDictionary.Add(key1, key2, value);

            AppendLine(isCommandSuccessful.ToString());
        }
예제 #6
0
        private static void ExecuteCommands(TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            int commandsCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < commandsCount; i++)
            {
                string commandLine = Console.ReadLine();
                ExecuteCommands(commandLine, twoKeysDictionary);
            }
        }
예제 #7
0
        private static void ExecuteValueCommand(string[] tokens, TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            int key1 = int.Parse(tokens[1]);
            int key2 = int.Parse(tokens[2]);

            try
            {
                int value = twoKeysDictionary[key1, key2];
                AppendLine(value.ToString());
            }
            catch (KeyNotFoundException knfe)
            {
                AppendLine(knfe.Message);
            }
        }
예제 #8
0
        private static void ExecuteCommands(string commandLine, TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            string[] tokens  = commandLine.Split();
            string   command = tokens[0];

            switch (command)
            {
            case "count":
                ExecuteCountCommand(twoKeysDictionary);
                break;

            case "contains":
                ExecuteContainsCommand(tokens, twoKeysDictionary);
                break;

            case "add":
                ExecuteAddCommand(tokens, twoKeysDictionary);
                break;

            case "remove":
                ExecuteRemoveCommand(tokens, twoKeysDictionary);
                break;

            case "clear":
                ExecuteClearCommand(twoKeysDictionary);
                break;

            case "value":
                ExecuteValueCommand(tokens, twoKeysDictionary);
                break;

            case "values":
                ExecuteValuesCommand(twoKeysDictionary);
                break;

            case "elements":
                ExecuteElementsCommand(twoKeysDictionary);
                break;

            default:
                break;
            }
        }
예제 #9
0
        private static void ExecuteCountCommand(TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            int count = twoKeysDictionary.Count;

            AppendLine(count.ToString());
        }
예제 #10
0
 private static void ExecuteValuesCommand(TwoKeysDictionary <int, int, int> twoKeysDictionary)
 {
     AppendLine(string.Join(", ", twoKeysDictionary.Values));
 }
예제 #11
0
 private static void ExecuteClearCommand(TwoKeysDictionary <int, int, int> twoKeysDictionary)
 {
     twoKeysDictionary.Clear();
 }