GerganaTsirkova

Be positive

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