Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApp15
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> input = Console.ReadLine().Split(' ').ToList();
- string[] command = Console.ReadLine().Split();
- while (command[0] != "3:1")
- {
- if (command[0] == "merge")
- {
- int startIndex = int.Parse(command[1]);
- int endIndex = int.Parse(command[2]);
- if (startIndex < 0)
- {
- startIndex = 0;
- }
- if (startIndex > input.Count - 1)
- {
- startIndex = input.Count - 1;
- }
- if (endIndex >= input.Count)
- {
- endIndex = input.Count - 1;
- }
- string mergedElements = string.Empty;
- for (int i = startIndex; i <= endIndex; i++)
- {
- mergedElements += input[i];
- }
- input.RemoveRange(startIndex, endIndex - startIndex + 1);
- input.Insert(startIndex, mergedElements);
- }
- else if (command[0] == "divide")
- {
- int index = int.Parse(command[1]);
- int partitions = int.Parse(command[2]);
- if (partitions == 0)
- {
- command = Console.ReadLine().Split();
- continue;
- }
- string divided = input[index];
- int step = divided.Length / partitions;
- List<string> cutted = new List<string>();
- if (input[index].Length % partitions == 0)
- {
- for (int i = 0; i < divided.Length; i += step)
- {
- cutted.Add(divided.Substring(i, step));
- }
- }
- else if (input[index].Length % partitions != 0)
- {
- for (int i = 0; i < divided.Length - 2; i += step)
- {
- cutted.Add(divided.Substring(i, step));
- }
- cutted.Add(divided.Substring(partitions - 1, divided.Length - (step + 1)));
- }
- input.RemoveAt(index);
- cutted.Reverse();
- for (int i = 0; i < cutted.Count; i++)
- {
- input.Insert(index, cutted[i]);
- }
- }
- command = Console.ReadLine().Split();
- }
- Console.WriteLine(string.Join(" ", input));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement