Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace AnonymusThreat
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> list = Console.ReadLine()
  12. .Split()
  13. .ToList();
  14.  
  15. string command = Console.ReadLine();
  16.  
  17. while (command != "3:1")
  18. {
  19. List<string> input = command
  20. .Split()
  21. .ToList();
  22.  
  23. if (input[0] == "merge")
  24. {
  25. int start = int.Parse(input[1]);
  26. if (start < 0 || start > list.Count - 1)
  27. {
  28. start = 0;
  29. }
  30.  
  31. int end = int.Parse(input[2]);
  32. if (end > list.Count - 1 || end < 0)
  33. {
  34. end = list.Count - 1;
  35. }
  36.  
  37. list = MergeIndex(list, start, end);
  38. }
  39. else if (input[0] == "divide")
  40. {
  41. int index = int.Parse(input[1]);
  42. int parts = int.Parse(input[2]);
  43.  
  44. list = DivideIndex(list, index, parts);
  45. }
  46.  
  47. command = Console.ReadLine();
  48. }
  49.  
  50. Console.WriteLine(string.Join(" ", list));
  51. }
  52.  
  53. //MERGE
  54. static List<string> MergeIndex(List<string> list, int start, int end)
  55. {
  56. int count = end - start;
  57.  
  58. for (int i = 0; i < list.Count; i++)
  59. {
  60. if (i == start)
  61. {
  62. for (int z = i + 1; z <= end; z++)
  63. {
  64. list[i] += list[z];
  65. }
  66. }
  67. }
  68.  
  69. list.RemoveRange(start + 1, count);
  70.  
  71. return list;
  72. }
  73.  
  74. //DIVIDE
  75. static List<string> DivideIndex(List<string> list, int index, int parts)
  76. {
  77. for (int i = 0; i < list.Count; i++)
  78. {
  79. if (i == index)
  80. {
  81.  
  82. string word = list[i];
  83.  
  84. if (word.Length % parts == 0)
  85. {
  86. int partitions = word.Length / parts;
  87.  
  88. for (int z = 0; z < parts; z++)
  89. {
  90. string sub = word.Substring(partitions * z, partitions);
  91. list.Insert(index + z, sub);
  92. }
  93. }
  94. else
  95. {
  96. int partitions = word.Length / parts;
  97. int counter = 0;
  98. for (int z = 0; z < parts; z++)
  99. {
  100. string sub = word.Substring(partitions * z, partitions);
  101. counter += partitions;
  102. if (z == parts - 1)
  103. {
  104. for (int x = counter; x < word.Length; x++)
  105. {
  106. sub += word[x];
  107. }
  108. }
  109. list.Insert(index + z, sub);
  110. }
  111. }
  112. }
  113. }
  114.  
  115. list.RemoveAt(index + parts);
  116. return list;
  117. }
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement