Advertisement
tanya_zheleva

Be Positive

Jan 29th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ExamPreparation
  6. {
  7.     class Startup
  8.     {
  9.         static void Main()
  10.         {
  11.             int countSequences = int.Parse(Console.ReadLine());
  12.  
  13.             for (int i = 0; i < countSequences; i++)
  14.             {
  15.                 int[] numbers = Console.ReadLine()
  16.                     .Trim()
  17.                     .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
  18.                     .Select(int.Parse)
  19.                     .ToArray();
  20.                 List<int> found = new List<int>();
  21.  
  22.                 for (int j = 0; j < numbers.Length; j++)
  23.                 {
  24.                     int currentNum = numbers[j];
  25.  
  26.                     if (currentNum >= 0)
  27.                     {
  28.                         found.Add(currentNum);
  29.                     }
  30.                     else
  31.                     {
  32.                         if (j + 1 < numbers.Length)
  33.                         {
  34.                             currentNum += numbers[j + 1];
  35.                         }
  36.  
  37.                         if (currentNum >= 0)
  38.                         {
  39.                             found.Add(currentNum);
  40.                         }
  41.  
  42.                         j++;
  43.                     }
  44.                 }
  45.  
  46.                 if (found.Any())
  47.                 {
  48.                     Console.WriteLine(string.Join(" ", found));
  49.                 }
  50.                 else
  51.                 {
  52.                     Console.WriteLine("(empty)");
  53.                 }
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement