Advertisement
bullit3189

Anonymous Threat - Lists

Jan 23rd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. namespace _08AnonymousThreat
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. List<string> initalData = Console.ReadLine().Split().ToList();
  13.  
  14. while (true)
  15. {
  16. string input = Console.ReadLine();
  17.  
  18. if (input=="3:1")
  19. {
  20. break;
  21. }
  22.  
  23. string[] token = input.Split();
  24.  
  25. string command = token[0];
  26.  
  27. if (command=="merge")
  28. {
  29. int startIndex =int.Parse(token[1]);
  30. int endIndex =int.Parse(token[2]);
  31.  
  32. if (startIndex < 0)
  33. {
  34. startIndex = 0;
  35. }
  36. if (endIndex > initalData.Count - 1)
  37. {
  38. endIndex = initalData.Count - 1;
  39. }
  40. if (startIndex > initalData.Count - 1 || endIndex < 0)
  41. {
  42. continue;
  43. }
  44.  
  45. Merge(initalData, startIndex, endIndex);
  46.  
  47. }
  48.  
  49. else
  50. {
  51. int startIndex = int.Parse(token[1]);
  52. int parts = int.Parse(token[2]);
  53.  
  54. Divide(initalData, startIndex, parts);
  55. }
  56. }
  57.  
  58. Console.WriteLine(string.Join(" ",initalData));
  59. }
  60.  
  61. private static void Divide(List<string> initalData, int startIndex, int parts)
  62. {
  63. string currWord = initalData[startIndex];
  64. int partLen = currWord.Length / parts;
  65.  
  66. List<string> newWords = new List<string>();
  67.  
  68. for (int i = 0; i < parts; i++)
  69. {
  70. string subWord = currWord.Substring(i * partLen, partLen);
  71.  
  72. if (i==parts-1)
  73. {
  74. subWord = currWord.Substring(i*partLen);
  75. }
  76.  
  77. newWords.Add(subWord);
  78. }
  79.  
  80. initalData.Remove(currWord);
  81. initalData.InsertRange(startIndex, newWords);
  82. }
  83.  
  84. private static void Merge(List<string> initalData, int startIndex, int endIndex)
  85. {
  86. string bigWord = string.Empty;
  87.  
  88. for (int i = startIndex; i <= endIndex; i++)
  89. {
  90. bigWord += initalData[i];
  91. }
  92.  
  93. initalData.RemoveRange(startIndex, endIndex - startIndex + 1);
  94. initalData.Insert(startIndex, bigWord);
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement