예제 #1
0
        public static void Editor()
        {
            var text = new BigList<string> ();
            string command = " ";
            do {
                command = Console.ReadLine();
                var parts = command.Split(' ');

                switch( parts[0]) {
                case "INSERT":
                    text.Add(parts[1]);
                    Console.WriteLine("OK");
                    break;

                case "APPEND":
                    text.AddToFront(parts[1]);
                    Console.WriteLine("OK");

                    break;

                case "DELETE":
                    try {
                        text.RemoveRange(int.Parse(parts[1]), int.Parse(parts[2]));
                        Console.WriteLine("OK");
                    }
                    catch(Exception) {
                        Console.WriteLine("ERROR");
                    }
                    break;
                }

            } while("PRINT" != command);
            Console.WriteLine (text);
        }
        static void Main()
        {
            BigList <string> textEditorial = new BigList <string>();
            string           command       = Console.ReadLine();

            while (command != "exit")
            {
                string[] commandargs        = command.Split(':');
                string   commandName        = commandargs[0];
                string   stringToManipulate = "";
                if (commandargs.Length > 1)
                {
                    stringToManipulate = commandargs[1].Trim();
                }
                switch (commandName)
                {
                case "INSERT":
                    textEditorial.AddToFront(stringToManipulate);
                    Console.WriteLine("OK");
                    break;

                case "APPEND":
                    textEditorial.Add(stringToManipulate);
                    Console.WriteLine("OK");
                    break;

                case "DELETE":
                    string[] deletionRange = stringToManipulate.Split(',');
                    int      from          = int.Parse(deletionRange[0]);
                    int      count         = int.Parse(deletionRange[1]);
                    try
                    {
                        textEditorial.RemoveRange(from, count);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("ERROR");
                    }
                    break;

                case "PRINT":
                    Console.WriteLine(string.Join(" ", textEditorial));
                    break;
                }
                command = Console.ReadLine();
            }
        }
예제 #3
0
        private static void Insert(string[] command)
        {
            int    position = int.Parse(command[1]);
            string name     = command[2];

            if (position == 0)
            {
                list.AddToFront(name);
                if (!bla.ContainsKey(name))
                {
                    bla.Add(name, 0);
                }

                bla[name]++;

                sb.AppendLine("OK");
            }
            else if (position == list.Count)
            {
                list.Add(name);
                if (!bla.ContainsKey(name))
                {
                    bla.Add(name, 0);
                }

                bla[name]++;

                sb.AppendLine("OK");
            }
            else if (position > list.Count)
            {
                sb.AppendLine("Error");
            }
            else
            {
                list.Insert(position, name);

                sb.AppendLine("OK");
                if (!bla.ContainsKey(name))
                {
                    bla.Add(name, 0);
                }

                bla[name]++;
            }
        }