Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<string> input = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- string command;
- while ((command = Console.ReadLine()) != "3:1")
- {
- string[] cmd = command.Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- if (cmd[0] == "merge")
- {
- int start = int.Parse(cmd[1]), end = int.Parse(cmd[2]);
- string temp = "";
- if ((start < 0 || start > input.Count - 1) &&
- (end < 0 || end > input.Count - 1))
- {
- continue;
- }
- else if (start < 0)
- {
- start = 0;
- }
- else if (end > input.Count - 1)
- {
- end = input.Count - 1;
- }
- for (int i = start; i <= end; i++)
- {
- temp += input[i];
- }
- input.RemoveRange(start, end - start + 1);
- input.Insert(start, temp);
- }
- else if (cmd[0] == "divide")
- {
- int idx = int.Parse(cmd[1]), parts = int.Parse(cmd[2]);
- string temp = input[idx]; //Chosen string for dividing
- if (parts > temp.Length)
- {
- parts = temp.Length;
- }
- string[] splited = new string[parts]; //result of splitting
- int partLength = temp.Length / parts; //symbols per part
- int reminder = temp.Length % parts; //for addition to the last part
- for (int i = 0; i < parts; i++)
- {
- for (int j = 0; j < partLength; j++)
- {
- splited[i] += temp[i * partLength + j];
- }
- }
- int reminderStartIx = parts * partLength;
- for (int i = reminderStartIx; i < reminderStartIx + reminder; i++)
- {
- splited[splited.Length - 1] += temp[i];
- }
- input.RemoveAt(idx); //Removing devided element
- input.InsertRange(idx, splited);
- }
- }
- Console.WriteLine(String.Join(" ", input));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement