Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace anonymousthreat
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string words = Console.ReadLine();
  14. string input = Console.ReadLine();
  15. while (input != @"3:1")
  16. {
  17. string[] commands = input.Split(' ').ToArray();
  18. string command = commands[0];
  19. int param1 = int.Parse(commands[1]);
  20. int param2 = int.Parse(commands[2]);
  21. if (command == "merge")
  22. {
  23. if (param1 <= words.Trim().Split(' ').Length - 1 && param1 >= 0)
  24. {
  25. if (param2 > words.Trim().Split(' ').Length - 1)
  26. {
  27. param2 = words.Trim().Split(' ').Length - 1;
  28. }
  29. if (param2 < 0)
  30. {
  31. param2 = 0;
  32. }
  33. words = Merge(param1, param2, words.Trim());
  34. }
  35. }
  36. if (command == "divide")
  37. {
  38. if (param1 <= words.Trim().Split(' ').ToArray().Length - 1 && param2 > 0 && param1 >= 0)
  39. {
  40. words = Divide(param1, param2, words.Trim());
  41. }
  42. }
  43. input = Console.ReadLine();
  44. }
  45. Console.WriteLine(words.Trim());
  46. }
  47.  
  48. private static string Divide(int index, int parts, string array)
  49. {
  50. string result = "";
  51. string start = "";
  52. string end = "";
  53. string[] words = array.Split(' ').ToArray();
  54. for (int i = 0; i < index; i++)
  55. {
  56. start = start + " " + words[i];
  57. }
  58. for (int i = index + 1; i <= words.Length - 1; i++)
  59. {
  60. end = end + " " + words[i];
  61. }
  62. string word2 = words[index];
  63. List<char> word = new List<char>();
  64. for (int i = 0; i < word2.Length; i++)
  65. {
  66. word.Add(word2[i]);
  67. }
  68. int part = word2.Length / parts;
  69. int lastPart = part + word2.Length % parts;
  70. string pieces = "";
  71. for (int i = 0; i < parts - 1; i++)
  72. {
  73. for (int j = 0; j < part; j++)
  74. {
  75. pieces = pieces + word[0];
  76. word.Remove(word[0]);
  77. }
  78. pieces = pieces + " ";
  79. }
  80. for (int i = 0; i < lastPart; i++)
  81. {
  82. pieces = pieces + word[i];
  83. }
  84. result = start.Trim() + " " + pieces.Trim() + " " + end.Trim();
  85. return result;
  86. }
  87.  
  88. private static string Merge(int indexStart, int indexEnd, string array)
  89. {
  90. string[] words = array.Split(' ').ToArray();
  91. string joined = "";
  92. string start = "", end = "";
  93. for (int i = 0; i < indexStart; i++)
  94. {
  95. start = start + " " + words[i];
  96. }
  97. for (int i = indexStart; i <= indexEnd; i++)
  98. {
  99. joined = joined + words[i];
  100. }
  101. for (int i = indexEnd + 1; i <= words.Length - 1; i++)
  102. {
  103. end = end + " " + words[i];
  104. }
  105. string[] final = { start.Trim(), joined, end.Trim() };
  106. string result = string.Join(" ", final);
  107. return result;
  108. }
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement