VelizarAvramov

17. ** Be Positive

Nov 25th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 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.             List<int> 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.             bool found = false;
  24.  
  25.             for (int j = 0; j < numbers.Count; j++)
  26.             {
  27.                 int currentNum = numbers[j];
  28.                 if (currentNum >= 0)
  29.                 {
  30.                     if (found)
  31.                     {
  32.                         Console.Write(" ");
  33.                     }
  34.                     Console.Write(currentNum);
  35.                     found = true;
  36.                 }
  37.                 else
  38.                 {
  39.                     if (j + 1 < numbers.Count)
  40.                     {
  41.                         currentNum += numbers[j + 1];
  42.                         j++;
  43.                     }
  44.                     if (currentNum >= 0)
  45.                     {
  46.                         if (found)
  47.                         {
  48.                             Console.Write(" ");
  49.                         }
  50.                         Console.Write(currentNum);
  51.                         found = true;
  52.                     }
  53.                 }
  54.             }
  55.            
  56.             if (!found)
  57.             {
  58.                 Console.WriteLine("(empty)");
  59.             }
  60.             else
  61.             {
  62.                 Console.WriteLine();
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment