danielaavramova

16. Be Positive

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