Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Numerics;
  6.  
  7. namespace TestGround
  8. {
  9. class Test
  10. {
  11. public static void Main()
  12. {
  13. int countSequences = int.Parse(Console.ReadLine());
  14.  
  15. for (int i = 0; i < countSequences; i++)
  16. {
  17. int[] input = Console.ReadLine().Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  18.  
  19. List<int> data = new List<int>();
  20.  
  21. for (int j = 0; j < input.Length - 1; j++)
  22. {
  23. int currentNum = input[j];
  24.  
  25. if (currentNum >= 0)
  26. {
  27. data.Add(currentNum);
  28. }
  29. else
  30. {
  31. currentNum += input[j + 1];
  32.  
  33. if (currentNum >= 0)
  34. {
  35. data.Add(currentNum);
  36. }
  37. j++;
  38. }
  39. }
  40.  
  41. if (input.Length > 2)
  42. {
  43.  
  44. if (( input[input.Length - 2] >= 0 && input[input.Length - 1] >= 0) || (input[input.Length - 3] < 0 && input[input.Length - 1] >= 0))
  45. {
  46. data.Add(input[input.Length - 1]);
  47. }
  48. }
  49. else if (input.Length == 2)
  50. {
  51. if (input[input.Length - 2] >= 0 && input[input.Length - 1] >= 0)
  52. {
  53. data.Add(input[input.Length - 1]);
  54. }
  55. }
  56. else
  57. {
  58. if (input[0] >= 0)
  59. {
  60. data.Add(input[0]);
  61. }
  62. }
  63.  
  64.  
  65. if (data.Count > 0)
  66. {
  67. Console.WriteLine(string.Join(" ", data));
  68. }
  69. else
  70. {
  71. Console.WriteLine("(empty)");
  72. }
  73. }
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement