Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Globalization;
- using System.Numerics;
- using System.Collections.Generic;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string text = Console.ReadLine();
- List<string> words = text.Split().ToList();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "3:1")
- {
- break;
- }
- string[] inputList = input.Split();
- string command = inputList[0];
- if (command == "merge")
- {
- int startIndex = int.Parse(inputList[1]);
- int endIndex = int.Parse(inputList[2]);
- if (startIndex >= 0 && startIndex < words.Count && endIndex >= 0)
- {
- Merge(words, startIndex, endIndex);
- }
- }
- else if (command == "divide")
- {
- int index = int.Parse(inputList[1]);
- int parts = int.Parse(inputList[2]);
- Divide(words, index, parts);
- }
- }
- Console.WriteLine(string.Join(" ", words));
- }
- private static void Merge(List<string> words, int startIndex, int endIndex)
- {
- if (startIndex < 0)
- {
- startIndex = 0;
- }
- if (endIndex > words.Count)
- {
- endIndex = words.Count - 1;
- }
- for (int i = startIndex + 1; i <= endIndex; i++)
- {
- words[startIndex] = string.Concat(words[startIndex], words[i]);
- words.RemoveAt(i);
- i--;
- endIndex--;
- }
- }
- private static void Divide(List<string> words, int index, int parts)
- {
- string word = words[index];
- string temp = string.Empty;
- List<string> tempList = new List<string>();
- words.RemoveAt(index);
- for (int i = 0; i < parts; i++)
- {
- if (i == parts - 1)
- {
- temp = word.Substring(i * (word.Length / parts));
- }
- else
- {
- temp = word.Substring(i * (word.Length / parts), (word.Length / parts));
- }
- tempList.Add(temp);
- }
- words.InsertRange(index, tempList);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement