Advertisement
angelllo

Anonymous Threat

Jun 20th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp15
  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();
  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 (startIndex < 0)
  23. {
  24. startIndex = 0;
  25. }
  26. if (startIndex > input.Count - 1)
  27. {
  28. startIndex = input.Count - 1;
  29. }
  30. if (endIndex >= input.Count)
  31. {
  32. endIndex = input.Count - 1;
  33. }
  34.  
  35. string mergedElements = string.Empty;
  36.  
  37. for (int i = startIndex; i <= endIndex; i++)
  38. {
  39. mergedElements += input[i];
  40. }
  41.  
  42. input.RemoveRange(startIndex, endIndex - startIndex + 1);
  43. input.Insert(startIndex, mergedElements);
  44.  
  45. }
  46. else if (command[0] == "divide")
  47. {
  48. int index = int.Parse(command[1]);
  49.  
  50. int partitions = int.Parse(command[2]);
  51.  
  52. if (partitions == 0)
  53. {
  54. command = Console.ReadLine().Split();
  55. continue;
  56. }
  57.  
  58. string divided = input[index];
  59. int step = divided.Length / partitions;
  60.  
  61. List<string> cutted = new List<string>();
  62.  
  63. if (input[index].Length % partitions == 0)
  64. {
  65.  
  66. for (int i = 0; i < divided.Length; i += step)
  67. {
  68. cutted.Add(divided.Substring(i, step));
  69. }
  70. }
  71.  
  72. else if (input[index].Length % partitions != 0)
  73. {
  74.  
  75. for (int i = 0; i < divided.Length - 2; i += step)
  76. {
  77. cutted.Add(divided.Substring(i, step));
  78. }
  79.  
  80. cutted.Add(divided.Substring(partitions - 1, divided.Length - (step + 1)));
  81. }
  82.  
  83. input.RemoveAt(index);
  84. cutted.Reverse();
  85.  
  86. for (int i = 0; i < cutted.Count; i++)
  87. {
  88. input.Insert(index, cutted[i]);
  89. }
  90. }
  91.  
  92. command = Console.ReadLine().Split();
  93. }
  94. Console.WriteLine(string.Join(" ", input));
  95.  
  96. }
  97.  
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement