Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.VisualBasic;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace _1.Anonymous_Treat
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> input = Console.ReadLine().Split(' ').ToList();
- string[] command = Console.ReadLine().Split(' ').ToArray();
- while (command[0] != "3:1")
- {
- if (command[0] == "merge")
- {
- StringBuilder str = new StringBuilder();
- int startIndex = int.Parse(command[1]);
- int endIndex = int.Parse(command[2]);
- if (startIndex <= input.Count-1)
- {
- if (startIndex < 0)
- {
- startIndex = 0;
- }
- if (endIndex >= input.Count-1)
- {
- endIndex = input.Count - 1;
- }
- for (int i = startIndex; i <= endIndex; i++)
- {
- str.Append(input[i]);
- }
- for (int i = endIndex; i >= startIndex; i--)
- {
- input.RemoveAt(i);
- }
- string merged = str.ToString();
- input.Insert(startIndex, merged);
- }
- }
- else if (command[0] == "divide")
- {
- List<string> inner = new List<string>();
- int index = int.Parse(command[1]);
- int partition = int.Parse(command[2]);
- if(partition > 0 )
- {
- string strToDivide = input[index].ToString();
- int counter = 0;
- StringBuilder str = new StringBuilder();
- for (int i = 0; i < strToDivide.Length; i++)
- {
- if (counter == (int)strToDivide.Length / partition)
- {
- if (i == strToDivide.Length - strToDivide.Length / partition)
- {
- inner.Add(str.ToString());
- counter = 0;
- str.Clear();
- for (int j = i; j < strToDivide.Length; j++)
- {
- str.Append(strToDivide[j]);
- }
- inner.Add(str.ToString());
- break;
- }
- else
- {
- inner.Add(str.ToString());
- counter = 0;
- str.Clear();
- str.Append(strToDivide[i]);
- counter++;
- }
- }
- else
- {
- str.Append(strToDivide[i]);
- counter++;
- }
- }
- input.RemoveAt(index);
- input.InsertRange(index, inner);
- }
- }
- command = Console.ReadLine().Split(' ').ToArray();
- }
- Console.WriteLine(string.Join(" ", input));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement