Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 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 Problem_2.Anonymous_Threat
  8. {
  9. class paramsInput
  10. {
  11. static void Main(string[] args)
  12. {
  13. string input = Console.ReadLine();
  14. //string[] paramsInput = input.Split(' ');
  15. List<string> paramsInput = input.Split(' ').ToList();
  16.  
  17. List<string> result = new List<string>();
  18.  
  19. string command = Console.ReadLine();
  20. while(command != "3:1")
  21. {
  22. string[] commandParams = command.Split(' ');
  23.  
  24. string commandName = commandParams[0];
  25. int startIndex = int.Parse(commandParams[1]);
  26. int endIndex = int.Parse(commandParams[2]);
  27.  
  28. //If any of the given indexes is out of the array, you must take ONLY the range that is INSIDE the array and merge it.
  29. if(startIndex < 0)
  30. {
  31. startIndex = 0;
  32. }
  33. if(startIndex > paramsInput.Count())
  34. {
  35. startIndex = paramsInput.Count();
  36. }
  37.  
  38. if (endIndex < 0)
  39. {
  40. endIndex = 0;
  41. }
  42. if (endIndex > paramsInput.Count())
  43. {
  44. endIndex = paramsInput.Count();
  45. }
  46.  
  47. // LOGIC
  48.  
  49. switch (commandName)
  50. {
  51. case "merge":
  52. string resultWord = string.Empty;
  53. for (int i = startIndex; i < endIndex+1; i++)
  54. {
  55. resultWord += paramsInput[i];
  56. }
  57.  
  58. paramsInput.RemoveRange(startIndex, endIndex+1);
  59. paramsInput.Insert(startIndex, resultWord);
  60.  
  61. // Console.WriteLine(resultWord);
  62. Console.WriteLine(string.Join(" ", paramsInput));
  63.  
  64. break;
  65. case "divide":
  66. break;
  67. default:
  68. Console.WriteLine("da go lapate");
  69. return;
  70. }
  71.  
  72. command = Console.ReadLine();
  73. }
  74.  
  75. // print
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement