Advertisement
koksibg

BePositive_broken

Oct 6th, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 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. namespace BePositive_broken
  8. {
  9.     class BePositive_broken
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int countSequences = int.Parse(Console.ReadLine());
  14.             for (int i = 0; i < countSequences; i++)
  15.             {
  16.                 string[] input = Console.ReadLine().Trim().Split(' ');
  17.                 var numbers = new List<int>();
  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.                 bool found = false;
  27.  
  28.                 for (int j = 0; j < numbers.Count; j++)
  29.                 {
  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
  45.                     {
  46.                         if (j < numbers.Count - 1)
  47.                         {
  48.                             currentNum += numbers[j + 1];
  49.                         }
  50.                         j++;
  51.                         if (currentNum >= 0)
  52.                         {
  53.                             if (found)
  54.                             {
  55.                                 Console.Write(" ");
  56.                             }
  57.  
  58.                             Console.Write(currentNum);
  59.  
  60.                             found = true;
  61.                         }
  62.                     }
  63.                 }
  64.  
  65.                 if (!found)
  66.                 {
  67.                     Console.WriteLine("(empty)");
  68.                 }
  69.                 else
  70.                 {
  71.                     Console.WriteLine();
  72.                 }
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement