Guest User

BePositive

a guest
Oct 3rd, 2016
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 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. public class BePositive
  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.             List<int> numbersToPrint = new List<int>();
  16.  
  17.             int[] numbers = Console.ReadLine()
  18.                 .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
  19.                 .Select(x => int.Parse(x))
  20.                 .ToArray();
  21.  
  22.             for (int j = 0; j < numbers.Length; j++)
  23.             {
  24.                 int currentNum = numbers[j];
  25.  
  26.                 if (currentNum >= 0)
  27.                 {
  28.                     numbersToPrint.Add(currentNum);
  29.                 }
  30.                 else
  31.                 {
  32.                     if (j == numbers.Length - 1)
  33.                     {
  34.                         break;
  35.                     }
  36.                     currentNum += numbers[j + 1];
  37.                     if (currentNum >= 0)
  38.                     {
  39.                         numbersToPrint.Add(currentNum);
  40.                     }
  41.                     j++;
  42.                 }
  43.             }
  44.  
  45.             if (numbersToPrint.Count > 0)
  46.             {
  47.                 Console.WriteLine(string.Join(" ", numbersToPrint));
  48.             }
  49.             else
  50.             {
  51.                 Console.WriteLine("(empty)");
  52.  
  53.             }
  54.         }
  55.     }
  56. }
Add Comment
Please, Sign In to add comment