Advertisement
nevenailievaa

08.AnonymousThreat

Feb 16th, 2023
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.51 KB | None | 0 0
  1. //INPUT
  2. List<string> list = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToList();
  3.  
  4. //ACTION
  5. string command = string.Empty;
  6.  
  7. while ((command = Console.ReadLine()) != "3:1")
  8. {
  9.     string[] commandArray = command.Split().ToArray();
  10.  
  11.     if (command.Contains("merge"))
  12.     {
  13.         int startIndex = Convert.ToInt32(commandArray[1]);
  14.         int endIndex = Convert.ToInt32(commandArray[2]);
  15.  
  16.         //Indexes Checker
  17.         if (list.Count > 1)
  18.         {
  19.             while (startIndex < 0 || startIndex >= list.Count - 1)
  20.             {
  21.                 if (startIndex < 0)
  22.                 {
  23.                     startIndex++;
  24.                 }
  25.                 else if (startIndex >= list.Count - 1)
  26.                 {
  27.                     startIndex--;
  28.                 }
  29.             }
  30.             while (endIndex >= list.Count || endIndex < 1)
  31.             {
  32.                 if (endIndex < 1)
  33.                 {
  34.                     endIndex++;
  35.                 }
  36.                 else if (endIndex >= list.Count)
  37.                 {
  38.                     endIndex--;
  39.                 }
  40.             }
  41.  
  42.             //Merger
  43.             for (int i = startIndex; i < endIndex; i++)
  44.             {
  45.                 list[startIndex] += $"{list[i+1]}";
  46.             }
  47.  
  48.             //Eraser
  49.             for (int j = 0; j < endIndex - startIndex; j++)
  50.             {
  51.                 list.RemoveAt(startIndex + 1);
  52.             }
  53.         }
  54.     }
  55.  
  56.     else if (command.Contains("divide"))
  57.     {
  58.         int index = Convert.ToInt32(commandArray[1]);
  59.         int partitions = Convert.ToInt32(commandArray[2]);
  60.  
  61.         //Text For Division
  62.         string textForDivision = list[index];
  63.         List<string> textList = new List<string>();
  64.         for (int i = 0; i < textForDivision.Length; i++)
  65.         {
  66.             textList.Add(textForDivision[i].ToString());
  67.         }
  68.  
  69.         //Division
  70.         string currentString = string.Empty;   
  71.         list.RemoveAt(index);
  72.  
  73.         //Even Digits
  74.         if (textList.Count % partitions == 0)
  75.         {
  76.             int lengthOfOneIndex = textList.Count / partitions;
  77.  
  78.             for (int i = partitions; i > 0; i--)
  79.             {
  80.                 for (int j = textList.Count - lengthOfOneIndex; j < textList.Count; j++)
  81.                 {
  82.                     currentString += $"{textList[j]}";
  83.                     textList.RemoveAt(j);
  84.                     j--;
  85.                 }
  86.                
  87.                 list.Insert(index, currentString);
  88.                 currentString = string.Empty;
  89.             }
  90.         }
  91.  
  92.         //Odd digits
  93.         else
  94.         {
  95.             int textListCount = textList.Count;
  96.             int numbersRemovedCounter = 0;
  97.             for (int i = textListCount - (textListCount % partitions); i < textListCount; i++)
  98.             {
  99.                 textList.RemoveAt(textListCount - (textListCount % partitions));
  100.                 numbersRemovedCounter++;
  101.             }
  102.  
  103.             int lengthOfOneIndex = textList.Count / partitions;
  104.  
  105.             for (int i = partitions; i > 0; i--)
  106.             {
  107.                 for (int j = textList.Count - lengthOfOneIndex; j < textList.Count; j++)
  108.                 {
  109.                     currentString += $"{textList[j]}";
  110.                     textList.RemoveAt(j);
  111.                     j--;
  112.                 }
  113.                 if (i == partitions)
  114.                 {
  115.                     for (int j = 0; j < numbersRemovedCounter; j++)
  116.                     {
  117.                         currentString += $"{textForDivision[textForDivision.Length-numbersRemovedCounter+j]}";
  118.                     }
  119.                 }
  120.  
  121.                 list.Insert(index, currentString);
  122.                 currentString = string.Empty;
  123.             }
  124.         }
  125.     }
  126. }
  127.  
  128. //OUTPUT
  129. Console.WriteLine(String.Join(" ", list));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement