Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace AnonymusThreat
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> list = Console.ReadLine()
- .Split()
- .ToList();
- string command = Console.ReadLine();
- while (command != "3:1")
- {
- List<string> input = command
- .Split()
- .ToList();
- if (input[0] == "merge")
- {
- int start = int.Parse(input[1]);
- if (start < 0 || start > list.Count - 1)
- {
- start = 0;
- }
- int end = int.Parse(input[2]);
- if (end > list.Count - 1 || end < 0)
- {
- end = list.Count - 1;
- }
- list = MergeIndex(list, start, end);
- }
- else if (input[0] == "divide")
- {
- int index = int.Parse(input[1]);
- int parts = int.Parse(input[2]);
- list = DivideIndex(list, index, parts);
- }
- command = Console.ReadLine();
- }
- Console.WriteLine(string.Join(" ", list));
- }
- //MERGE
- static List<string> MergeIndex(List<string> list, int start, int end)
- {
- int count = end - start;
- for (int i = 0; i < list.Count; i++)
- {
- if (i == start)
- {
- for (int z = i + 1; z <= end; z++)
- {
- list[i] += list[z];
- }
- }
- }
- list.RemoveRange(start + 1, count);
- return list;
- }
- //DIVIDE
- static List<string> DivideIndex(List<string> list, int index, int parts)
- {
- for (int i = 0; i < list.Count; i++)
- {
- if (i == index)
- {
- string word = list[i];
- if (word.Length % parts == 0)
- {
- int partitions = word.Length / parts;
- for (int z = 0; z < parts; z++)
- {
- string sub = word.Substring(partitions * z, partitions);
- list.Insert(index + z, sub);
- }
- }
- else
- {
- int partitions = word.Length / parts;
- int counter = 0;
- for (int z = 0; z < parts; z++)
- {
- string sub = word.Substring(partitions * z, partitions);
- counter += partitions;
- if (z == parts - 1)
- {
- for (int x = counter; x < word.Length; x++)
- {
- sub += word[x];
- }
- }
- list.Insert(index + z, sub);
- }
- }
- }
- }
- list.RemoveAt(index + parts);
- return list;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement