Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace AnonymousThreat
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> input = Console.ReadLine().Split().ToList();
  12.  
  13.             string[] command = Console.ReadLine().Split().ToArray();
  14.  
  15.             while (command[0] != "3:1")
  16.             {
  17.                 if (command[0] == "merge")
  18.                 {
  19.                     int startIndex = int.Parse(command[1]);
  20.                     int endIndex = int.Parse(command[2]);
  21.  
  22.                     if (endIndex > input.Count - 1) endIndex = input.Count - 1;
  23.                     if (startIndex < 0 || startIndex > endIndex) startIndex = 0;
  24.  
  25.                     string merge = "";
  26.  
  27.  
  28.                     for (int i = startIndex; i <= endIndex; i++)
  29.                     {
  30.                         merge += input[startIndex];
  31.                         input.RemoveAt(startIndex);
  32.                     }
  33.                     input.Insert(startIndex, merge);
  34.                 }
  35.                 else if (command[0] == "divide")
  36.                 {
  37.                     int index = int.Parse(command[1]);
  38.                     int parts = int.Parse(command[2]);
  39.                     string element = input[index];
  40.                     input.RemoveAt(index);
  41.  
  42.                     if (element.Length % parts == 0)
  43.                     {
  44.                         int countOfDigitsPerPart = element.Length / parts;
  45.                         string currentElement = "";
  46.  
  47.                         for (int i = 0; i < element.Length; i++)
  48.                         {
  49.                             currentElement += element[i];
  50.                             if ((i + 1) % countOfDigitsPerPart == 0)
  51.                             {
  52.                                 input.Insert(index, currentElement);
  53.                                 currentElement = "";
  54.                                 index++;
  55.                             }
  56.                         }
  57.                     }
  58.                     else
  59.                     {
  60.                         int countOfDigitsPerPart = element.Length / parts;
  61.                         string currentElement = "";
  62.  
  63.                         for (int i = 0; i < element.Length; i++)
  64.                         {
  65.                             if (i < element.Length - 1 - countOfDigitsPerPart)
  66.                             {
  67.                                 currentElement += element[i];
  68.  
  69.                                 if ((i + 1) % countOfDigitsPerPart == 0)
  70.                                 {
  71.                                     input.Insert(index, currentElement);
  72.                                     currentElement = "";
  73.                                     index++;
  74.                                 }
  75.                             }
  76.                             else
  77.                             {
  78.                                 currentElement += element[i];
  79.                                 if (i == element.Length - 1)
  80.                                 {
  81.                                     input.Insert(index, currentElement);
  82.                                 }
  83.                             }
  84.                         }
  85.                     }
  86.                 }
  87.                 command = Console.ReadLine().Split().ToArray();
  88.             }
  89.             Console.WriteLine(string.Join(" ", input));
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement