Guest User

Untitled

a guest
Jan 16th, 2018
1,073
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp10
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<string> input = Console.ReadLine().Split().ToList();
  14.  
  15. while (true)
  16. {
  17. string[] commands = Console.ReadLine().Split();
  18. string command = commands[0];
  19. if (command == "3:1")
  20. {
  21. break;
  22. }
  23. int startIndex = int.Parse(commands[1]);
  24. int endIndex = int.Parse(commands[2]);
  25. string concatWord = string.Empty;
  26. if (endIndex > input.Count - 1 || endIndex < 0)
  27. {
  28. endIndex = input.Count - 1;
  29. }
  30. if (startIndex < 0 || startIndex > input.Count)
  31. {
  32. startIndex = 0;
  33. }
  34.  
  35. if (command == "merge")
  36. {
  37. for (int i = startIndex; i <= endIndex; i++)
  38. {
  39. concatWord += input[i];
  40. }
  41. input.RemoveRange(startIndex, endIndex - startIndex + 1);
  42. input.Insert(startIndex, concatWord);
  43.  
  44. }
  45. else if (command == "divide")
  46. {
  47. List<string> divided = new List<string>();
  48. int divide = int.Parse(commands[2]);
  49. string word = input[startIndex];
  50. input.RemoveAt(startIndex);
  51. int parts = word.Length / divide;
  52. for (int i = 0; i < divide; i++)
  53. {
  54. if (i== divide -1)
  55. {
  56. divided.Add(word.Substring(i * parts));
  57. }
  58. else
  59. {
  60. divided.Add(word.Substring(i * parts, parts));
  61. }
  62. // string element = word.Substring(0, parts);
  63. // word = word.Substring(parts);
  64. // divided.Add(element);
  65. }
  66. input.InsertRange(startIndex, divided);
  67. }
  68.  
  69.  
  70. }
  71.  
  72. Console.WriteLine(string.Join(" ", input));
  73. }
  74. }
  75. }
RAW Paste Data