Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Anonymous_threat_3
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> code = Console.ReadLine().Split().ToList();
- string[] command = Console.ReadLine().Split(' ').ToArray();
- while (command[0]!="3:1")
- {
- int input1 = int.Parse(command[1]);
- int input2 = int.Parse(command[2]);
- if (command[0] == "merge")
- {
- merge(code, input1, input2);
- }
- else
- {
- divide(code, input1, input2);
- }
- command = Console.ReadLine().Split(' ').ToArray();
- }
- Console.WriteLine(string.Join(" ", code));
- }
- static void divide(List<string> code, int index, int partitions)
- {
- if (index< 0)
- {
- index = 0;
- }
- List<string>dividing = new List<string>();
- string word = code[index];
- if (index > word.Length-1)
- {
- index = word.Length - 1;
- }
- int counterTemporary = 0;
- char[] wordChars = new char[word.Length];
- if (wordChars.Length<partitions)
- {
- return;
- }
- for (int i = 0; i < word.Length; i++)
- {
- wordChars[i] = word[i];
- }
- if (wordChars.Length % partitions==0)
- {
- string[] temporary = new string[wordChars.Length / partitions];
- for (int i = 0; i < wordChars.Length; i++)
- {
- temporary[counterTemporary] = wordChars[i].ToString();
- if (((i + 1) % (wordChars.Length / partitions)) == 0)
- {
- dividing.Add(string.Join("", temporary));
- counterTemporary = 0;
- }
- else
- {
- counterTemporary++;
- }
- }
- }
- else if (wordChars.Length%partitions!=0)
- {
- for (int i = 0; i < partitions-1; i++)
- {
- dividing.Add(wordChars[i].ToString());
- counterTemporary++;
- }
- string[] temporary = new string[wordChars.Length - counterTemporary];
- for (int i = counterTemporary; i < wordChars.Length; i++)
- {
- temporary[i-counterTemporary] = wordChars[i].ToString();
- if (i == wordChars.Length-1)
- {
- dividing.Add(string.Join("", temporary));
- }
- }
- }
- code.RemoveAt(index);
- code.InsertRange(index, dividing);
- }
- static void merge(List<string> code, int input1, int input2)
- {
- if (input1 < 0)
- {
- input1 = 0;
- }
- if (input2 > code.Count -1)
- {
- input2 = code.Count-1;
- }
- if (input2 < 0)
- {
- input2 = 0;
- }
- if (input1>=input2)
- {
- return;
- }
- string[] merging = new string[input2 - input1+1];
- for (int i = input1; i <= input2; i++)
- {
- merging[i - input1] = code[input1];
- code.RemoveAt(input1);
- }
- string merged = string.Join("", merging);
- code.InsertRange(input1, merged.Split().ToList());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement