martinvalchev

Be_Positive

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